// C++ code
//
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Keypad.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>  // include Adafruit SSD1306 OLED display driver
#include "RTClib.h"
#include <SD.h>
#include <EEPROM.h>

File myFile;
File bmp;

#define SADR	0x20 // Address of PCF8574 (8-bit I/O Expander)

#define NEO_LED_COUNT 16 // Number of Neopixels


#define NEO0 A0 // Neopixel Strip Pin
#define SPK0 A1 // Pizeo Electric Buzzer Pin
#define TMP0 A3 // Tempeture Sensor Pin
#define UDS0 A2 // Ultrasonic Distance Sensor Pin
#define LED0 10 // LED 0 Pin (AKA Status Led).
#define BTN0 11 // Button 0 Pin (Left)
#define BTN1 12 // Button 1 Pin (Center)
#define BTN2 13 // Button 2 Pin (Right)

#define OLED_WIDTH 128 // OLED display width, in pixels
#define OLED_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 oled_1(OLED_WIDTH, OLED_HEIGHT, &Wire, OLED_RESET);
int oled = 0;
int x=0;
void bitmap(char* fle,int groundUp)
{
  char bootfile[32];
  sprintf(bootfile, "%s", fle);
  SD.begin();
  myFile = SD.open(bootfile);
  if (myFile) {
    x=0;
    int y=0;
    if(groundUp == 0)
    {
      y=0;
    }
    else {
      y=64;
    }
    int addr=0x00;
    oled_1.clearDisplay();
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      unsigned char readB = myFile.read();
      if(readB > 0)
      {
        oled_1.drawPixel(x,y,1);
      }
      else {
        oled_1.drawPixel(x,y,0);
      }
      if(y >= 63)
      {
        oled_1.display();
        //delay(10);
        y=-1;
        x=0;
      }
      x++;
      if(x >= 128)
      {
        if(groundUp == 0)
        {
          y++;
        }
        else {
          y--;
        }
        x=0;
      }
    }
    delay(1000);
  }
}
void setup()
{
  oled_1.begin(SSD1306_SWITCHCAPVCC, 60);
  bitmap("bootup.bin",0);
  delay(1000);
}

// Handle I2C GPIO

void loop()
{
  for(int y=0; y<=64; y++)
  {
    for(int x=0; x<=128; x++)
    {
      oled_1.drawPixel(x, y, random(2));
    }
  }
  oled_1.display();
}
GND5VSDASCLSQWRTCDS1307+