/* ESP32 HTTP IoT Server Example for Wokwi.com
https://wokwi.com/projects/320964045035274834
To test, you need the Wokwi IoT Gateway, as explained here:
https://docs.wokwi.com/guides/esp32-wifi#the-private-gateway
Then start the simulation, and open http://localhost:9080
in another browser tab.
Note that the IoT Gateway requires a Wokwi Club subscription.
To purchase a Wokwi Club subscription, go to https://wokwi.com/club
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MPU6050_light.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1 // Reset pin
#define SCREEN_ADDRESS 0x3C
#define BUTTON_PIN 34
#define analogInPin A0
#define FRAME_DELAY (42)
#define FRAME_WIDTH (48)
#define FRAME_HEIGHT (48)
#define FRAME_COUNT (sizeof(frames) / sizeof(frames[0]))
static const unsigned char PROGMEM nonclockwise[] = {0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x7f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x7f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x3f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x3f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xfc,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xfc,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xfe,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xfe,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff};
static const unsigned char PROGMEM clockwise[] = {0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xfe,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xfe,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xfc,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xfc,0x3f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x3f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x7f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x7f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20};
const byte PROGMEM frames[][288] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,7,230,65,134,99,248,7,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,0,102,65,134,99,248,0,3,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,0,51,1,0,0,0,0,51,1,128,0,0,12,99,3,128,0,0,12,99,3,192,0,0,6,99,3,192,0,0,6,97,134,192,0,0,6,65,134,99,248,0,3,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,0,51,1,0,0,0,0,51,1,128,0,0,0,99,3,128,0,0,0,99,3,192,0,0,0,99,3,192,0,0,0,97,134,192,0,0,0,65,134,99,248,0,0,193,134,103,248,0,0,193,140,110,0,0,0,193,140,60,0,0,0,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,0,19,1,0,0,0,0,3,1,128,0,0,0,3,3,128,0,0,0,3,3,192,0,0,0,3,3,192,0,0,0,1,134,192,0,0,0,1,134,99,248,0,0,1,134,103,248,0,0,1,140,110,0,0,0,1,140,60,0,0,0,1,140,56,0,0,0,0,216,56,0,0,0,0,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,0,0,0,0,28,51,0,0,0,0,28,99,0,0,0,0,60,99,0,0,0,0,54,99,0,0,0,0,102,97,128,0,0,31,230,65,128,0,0,31,195,193,128,0,0,0,3,193,128,0,0,0,3,193,128,0,0,0,1,193,128,0,0,0,1,128,192,0,0,0,0,128,192,0,0,0,0,0,192,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,0,0,0,0,28,51,0,0,0,0,28,99,3,0,0,0,60,99,3,0,0,0,54,99,3,0,0,0,102,97,134,0,0,31,230,65,134,0,0,31,195,193,134,0,0,0,3,193,140,0,0,0,3,193,140,0,0,0,1,193,140,0,0,0,1,128,216,0,0,0,0,128,216,0,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,96,0,31,195,193,134,96,0,0,3,193,140,96,0,0,3,193,140,32,0,0,1,193,140,0,0,0,1,128,216,0,0,0,0,128,216,0,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,96,0,31,195,193,134,102,0,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,224,31,195,193,134,103,224,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,12,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,30,0,0,0,0,0,54,0,0,0,0,0,51,0,0,0,0,8,51,1,0,0,0,28,51,1,128,0,0,28,99,3,128,0,0,60,99,3,192,0,0,54,99,3,192,0,0,102,97,134,192,0,31,230,65,134,99,248,31,195,193,134,103,248,0,3,193,140,110,0,0,3,193,140,60,0,0,1,193,140,56,0,0,1,128,216,56,0,0,0,128,216,16,0,0,0,0,216,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,240,0,0,0,0,0,112,0,0,0,0,0,96,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// 'all_btt', 128x64px
static const unsigned char PROGMEM image_paint_0_bits[] = {0xff,0xff,0xc0,0x80,0x00,0x40,0x80,0x00,0x78,0x80,0x00,0x48,0x80,0x00,0x48,0x80,0x00,0x48,0x80,0x00,0x48,0x80,0x00,0x78,0x80,0x00,0x40,0xff,0xff,0xc0};
MPU6050 mpu(Wire);
const int mpuAddr = 0x68; // I2C address
unsigned long previousMillis;
const unsigned long interval = 1000 ;
float lastState = 0;
void calc_voltage(){
unsigned long currentMillis = millis();
// int sensorValue;
// sensorValue = analogRead(analogInPin);
// float voltage = sensorValue / 4095 * 3.3;
display.drawBitmap(105, 1, image_paint_0_bits, 21, 10, 1);
display.display();
float voltage = 3.0;
float bar_value = mapfloat(voltage, 2.7,3.3,0,5);
// if(lastState != bar_value){
// Serial.print("Voltage: ");
// Serial.println(bar_value);
// Serial.println(lastState);
for(int i = 1; i <= bar_value; i++){
display.drawRect(104 + (i * 3),3,2,6,1);
}
display.display();
// lastState = bar_value;
// }
if(bar_value < 1){
if(currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
display.drawBitmap(105, 1, image_paint_0_bits, 21, 10, 0);
display.display();
// delay(1000);
}
}
}
int frame = 0;
void splash(){
display.clearDisplay();
display.drawBitmap(40, 8, frames[frame], FRAME_WIDTH, FRAME_HEIGHT, 1);
display.display();
frame = (frame + 1) % FRAME_COUNT;
delay(3000);
display.clearDisplay();
}
void calibrate(){
// Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets(); // gyro and accelero
// Serial.println("Done!\n");
}
void setup(void) {
Serial.begin(9600);
Wire.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
// Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Clear the buffer.
display.clearDisplay();
splash();
byte status = mpu.begin();
// Serial.print(F("MPU6050 status: "));
// Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050
calibrate();
// initialize the OLED object
// The setup() took so long,
// set previousMillis to a fresh value.
previousMillis = millis();
randomSeed(analogRead(0));
}
int number = 0;
int last_number = 0;
float num_pos = 48;
float grade_pos = 72;
void loop(void) {
mpu.update();
calc_voltage();
display.setTextColor(WHITE);
if (number >= 10) {
num_pos = 35;
grade_pos = 83;
}
else{
num_pos = 48;
grade_pos = 72;
}
display.setTextColor(1);
display.setTextSize(4);
display.setTextWrap(false);
display.setCursor(num_pos, 29);
display.print(number);
display.setTextSize(2);
display.setCursor(grade_pos, 12);
display.print("o");
// int value = digitalRead((BUTTON_PIN));
// if (lastState != value) {
// lastState = value;
// if (value == LOW){
// number += 1;
// display.clearDisplay();
// }
// }
number = round(mpu.getAngleX());
if(number < 0){
number *= -1;
}
if(number > 0 )
if(last_number != number){
last_number = number;
display.clearDisplay();
}
// Serial.print(F("ANGLE="));
// Serial.print(number);
// Serial.println();
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}