// 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
#define LED_PIN 6
#define LED_COUNT 1
Adafruit_NeoPixel neoPixel( LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int potpin = A3;
// Set the origin in the middle of the display
const int xOrigin = 64;
const int yOrigin = 16;
int bar1a = 1;
int bar1b = 1;
int bar2a = 1;
int bar3a = 1;
int bar4a = 1;
int bar5a = 1;
int bar6a = 1;
int bar7a = 1;
int bar8a = 1;
int bar9a = 1;
int bar10a = 1;
int bar11a = 1;
int bar12a = 1;
int bar13a = 1;
int bar14a = 1;
int bar15a = 1;
int bar16a = 1;
int bar17a = 1;
int bar18a = 1;
int bar19a = 1;
int bar20a = 1;
int bar21a = 1;
int bar22a = 1;
int bar23a = 1;
int bar24a = 1;
int bar25a = 1;
int bar26a = 1;
int bar27a = 1;
int bar28a = 1;
int bar29a = 1;
int bar30a = 1;
int bar31a = 1;
int bar32a = 1;
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);
// Initialize the NeoPixel
neoPixel.begin();
}
void loop()
{
draw_wireframe();
bar1a = analogRead(potpin);
bar1a = map(bar1a, 0, 1023, 0, 64);
bar32a = bar31a;
bar31a = bar30a;
bar30a = bar29a;
bar29a = bar28a;
bar28a = bar27a;
bar27a = bar26a;
bar26a = bar25a;
bar25a = bar24a;
bar24a = bar23a;
bar23a = bar22a;
bar22a = bar21a;
bar21a = bar20a;
bar20a = bar19a;
bar19a = bar18a;
bar18a = bar17a;
bar17a = bar16a;
bar16a = bar15a;
bar15a = bar14a;
bar14a = bar13a;
bar13a = bar12a;
bar12a = bar11a;
bar11a = bar10a;
bar10a = bar9a;
bar9a = bar8a;
bar8a = bar7a;
bar7a = bar6a;
bar6a = bar5a;
bar5a = bar4a;
bar4a = bar3a;
bar3a = bar2a;
bar2a = bar1a;
//bar1a = analogRead(potpin);
/*
bar1a = bar1a + bar1b;
if (bar1a >= 30){
bar1b = random(-1,-5);
}
else if(bar1a <=1){
bar1b = random(1,5);
}
/*
bar2a = bar2a + bar2b;
//}
if (bar2a >= 22){
bar2b = random(-1,-5);
}
else if(bar2a <=1){
bar2b = random(1,3);
}
bar3a = bar3a + bar3b;
//}
if (bar3a >= 22){
bar3b = random(-1,-3);
}
else if(bar1a <=1){
bar3b = random(1,5);
}
*/
}
void draw_wireframe(void)
{
// Start with a empty buffer
display.clearDisplay();
display.fillRect(0, 30, 2, 32, SSD1306_WHITE );
display.fillRect(2, 30, 2, 32, SSD1306_WHITE );
display.fillRect(4, 30, 2, 32, SSD1306_WHITE );
display.fillRect(6, 30, 2, 32, SSD1306_WHITE );
display.fillRect(8, 30, 2, 32, SSD1306_WHITE );
display.fillRect(10, 30, 2, 32, SSD1306_WHITE );
display.fillRect(12, 30, 2, 32, SSD1306_WHITE );
display.fillRect(14, 30, 2, 32, SSD1306_WHITE );
display.fillRect(16, 30, 2, 32, SSD1306_WHITE );
display.fillRect(18, 30, 2, 32, SSD1306_WHITE );
display.fillRect(20, 30, 2, 32, SSD1306_WHITE );
display.fillRect(22, 30, 2, 32, SSD1306_WHITE );
display.fillRect(24, 30, 2, 32, SSD1306_WHITE );
display.fillRect(26, 30, 2, 32, SSD1306_WHITE );
display.fillRect(28, 30, 2, 32, SSD1306_WHITE );
display.fillRect(30, 30, 2, 32, SSD1306_WHITE );
display.fillRect(32, 30, 2, 32, SSD1306_WHITE );
display.fillRect(34, 30, 2, 32, SSD1306_WHITE );
display.fillRect(36, 30, 2, 32, SSD1306_WHITE );
display.fillRect(38, 30, 2, 32, SSD1306_WHITE );
display.fillRect(40, 30, 2, 32, SSD1306_WHITE );
display.fillRect(42, 30, 2, 32, SSD1306_WHITE );
display.fillRect(44, 30, 2, 32, SSD1306_WHITE );
display.fillRect(46, 30, 2, 32, SSD1306_WHITE );
display.fillRect(48, 30, 2, 32, SSD1306_WHITE );
display.fillRect(50, 30, 2, 32, SSD1306_WHITE );
display.fillRect(52, 30, 2, 32, SSD1306_WHITE );
display.fillRect(54, 30, 2, 32, SSD1306_WHITE );
display.fillRect(56, 30, 2, 32, SSD1306_WHITE );
display.fillRect(58, 30, 2, 32, SSD1306_WHITE );
display.fillRect(60, 30, 2, 32, SSD1306_WHITE );
display.fillRect(62, 30, 2, 32, SSD1306_WHITE );
display.fillRect( 0 , 30, 2, bar1a, SSD1306_BLACK );
display.fillRect( 2 , 30, 2, bar2a, SSD1306_BLACK );
display.fillRect( 4 , 30, 2, bar3a, SSD1306_BLACK );
display.fillRect( 6 , 30, 2, bar4a, SSD1306_BLACK );
display.fillRect( 8 , 30, 2, bar5a, SSD1306_BLACK );
display.fillRect( 10 , 30, 2, bar6a, SSD1306_BLACK );
display.fillRect( 12 , 30, 2, bar7a, SSD1306_BLACK );
display.fillRect( 14 , 30, 2, bar8a, SSD1306_BLACK );
display.fillRect( 16 , 30, 2, bar9a, SSD1306_BLACK );
display.fillRect( 18 , 30, 2, bar10a, SSD1306_BLACK );
display.fillRect( 20 , 30, 2, bar11a, SSD1306_BLACK );
display.fillRect( 22 , 30, 2, bar12a, SSD1306_BLACK );
display.fillRect( 24 , 30, 2, bar13a, SSD1306_BLACK );
display.fillRect( 26 , 30, 2, bar14a, SSD1306_BLACK );
display.fillRect( 28 , 30, 2, bar15a, SSD1306_BLACK );
display.fillRect( 30 , 30, 2, bar16a, SSD1306_BLACK );
display.fillRect( 32 , 30, 2, bar17a, SSD1306_BLACK );
display.fillRect( 34 , 30, 2, bar18a, SSD1306_BLACK );
display.fillRect( 36 , 30, 2, bar19a, SSD1306_BLACK );
display.fillRect( 38 , 30, 2, bar20a, SSD1306_BLACK );
display.fillRect( 40 , 30, 2, bar21a, SSD1306_BLACK );
display.fillRect( 42 , 30, 2, bar22a, SSD1306_BLACK );
display.fillRect( 44 , 30, 2, bar23a, SSD1306_BLACK );
display.fillRect( 46 , 30, 2, bar24a, SSD1306_BLACK );
display.fillRect( 48 , 30, 2, bar25a, SSD1306_BLACK );
display.fillRect( 50 , 30, 2, bar26a, SSD1306_BLACK );
display.fillRect( 52 , 30, 2, bar27a, SSD1306_BLACK );
display.fillRect( 54 , 30, 2, bar28a, SSD1306_BLACK );
display.fillRect( 56 , 30, 2, bar29a, SSD1306_BLACK );
display.fillRect( 58 , 30, 2, bar30a, SSD1306_BLACK );
display.fillRect( 60 , 30, 2, bar31a, SSD1306_BLACK );
display.fillRect( 62 , 30, 2, bar32a, SSD1306_BLACK );
// display.fillRect(00, 30, bar1a, 10, SSD1306_WHITE );
//delay (500);
// Write the new picture to the display
display.display();
}