//------------------------------------------------------------------------- 
// 2022/01/24
// 
// S James Parsons Jr
// www.sjamesparsonsjr.com
//
//------------------------------------------------------------------------- 
// +++ NOTES +++
//Basic SSD1306 manual https://learn.adafruit.com/adafruit-gfx-graphics-library/graphics-primitives 
// Image to Binary https://www.dcode.fr/binary-image
// image to binary https://www.mischianti.org/2021/07/14/ssd1306-oled-display-draw-images-splash-and-animations-2/
// SSD1306 Datasheet https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf

//------------------------------------------------------------------------- 
// +++ Libraries +++
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//------------------------------------------------------------------------- 
// +++ Variables +++
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     8 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int CurrentScreen;


#define LOGO_WIDTH    128
#define LOGO_HEIGHT   64

#define LED 13

// Window Variables
PROGMEM String ScreenWindows[6] = {"Home","Screen 1", "Screen 2", "Screen 3", "Screen 4", "Screen 5"};
int windowVariable = 0; //sizeof(ScreenWindows[0]);

// Button Array Variables
byte buttons[] = {2,3,4,5}; // pin numbers of the buttons that we'll use
#define NUMBUTTONS sizeof(buttons)
int buttonState[NUMBUTTONS];
int lastButtonState[NUMBUTTONS];
boolean buttonIsPressed[NUMBUTTONS];  
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 100; // the debounce time; increase if the output flickers

//------------------------------------------------------------------------- 
// +++ Functions +++


//------------------------------------------------------------------------- 
// +++ Setup +++
void setup() {
  Serial.begin(9600);  // For Arduino Uno ||  Serial.begin(115200) // ESP32

  pinMode(LED_BUILTIN, OUTPUT);
  for (int i=0; i<(NUMBUTTONS-1); i++) {
    pinMode(i, INPUT);
    lastButtonState[i]=LOW;
    buttonIsPressed[i]=false; 
    }
  //SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
  //   for(;;); // Don't proceed, loop forever
  }
  drawSplash();
  delay(1000); 

  Screen(0);
  delay(1000);

  Screen(1);
  delay(500);
}

//------------------------------------------------------------------------- 
// +++ Loop +++
void loop() {
  check_buttons();
  action();

}

 
//Build a list of menu items in an array.  Called MainMenuList -- https://www.arduino.cc/reference/en/language/variables/data-types/string/