// Example sketch for the MPU-6050.
//
// Version 1, 9 August 2021, by Koepel with help from Wokwi community.
//
// Start the simulation and click on the MPU-6050 module to change the values.
//
// Note:
// This example does not use a library with quaternations for the 3D orientation.
// The values are directly read from the MPU-6050 and are used to rotate a cube.
// It is just a fun example. The rotation of the cube is not according to the
// physical values of the accelerometer and the gyro.
//
// Based on:
// (1)
// 3D_Cube for Arduino OLED module by Colin Ord, 9/1/2015
// A port of my (Colin Ord) original JustBasic Cube_3D demo to the Arduino Uno using U8G library.
// http://colinord.blogspot.com/2015/01/arduino-oled-module-with-3d-demo.html
// (no known copyrights)
//
// (2)
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
// https://playground.arduino.cc/Main/MPU-6050/#short
//
// (3)
// The Adafruit GFX library with the SSD1306 driver.
//
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoPixel.h>
Adafruit_SSD1306 display( 128, 64); // 128 pixels width, 64 pixels height
int potpin = A3;
// Set the origin in the middle of the display
int range = 0;
int rangernd = 0;
int dive = 10;
int dive1 = 0;
const float viewDistance = 150.0; // higher for less perspective, lower for more.
void setup()
{
Serial.begin( 115200);
// Initialize the OLED display and test if it is connected.
if( !display.begin( SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F( "SSD1306 allocation failed"));
for(;;); // halt the sketch if error encountered
}
// bar1a = random(0,22);
display.clearDisplay();
}
void randplus(){
rangernd = range + random(0,3);
}
void randminus(){
rangernd = range - random(0,3);
}
void loop()
{
range = analogRead(potpin);
range = map(range, 0, 1023, 0, 128);
// Start with a empty buffer
display.drawCircle(64, 0, range, SSD1306_WHITE );
display.clearDisplay();
Serial.print("range ");
Serial.println(range);
for(int i = 0; i <= 128; i++){
range = analogRead(potpin);
range = map(range, 0, 1023, 0, 128);
switch (random(1,2)) {
//select size of phrase
case 1:randplus(); break;
case 2:randminus(); break;
}
rangernd;
display.fillRect(i, 0, i + 8, range - (range/dive), SSD1306_WHITE );
display.drawCircle(64, 0, range, SSD1306_WHITE );
Serial.print("range for ");
Serial.println(range);
Serial.print("i ");
Serial.println(i);
if(i < 64){
dive = dive+1;
}
if(i > 64){
dive = dive-1;
}
if(dive == 0){
dive=1;
}
else if(dive >=128){
dive=128;
}
i=i+8;
}
display.display();
}