#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include "Led.h"

#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            -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int ledsNumber=6;                  //number of leds
int break_line = 3;
const int centerX[3]={21,63,105};  //array with the center x coordinate for each led
const int centerY[2] = {10, 45};
const char name[6]={'R','G','B', 'C', 'Y', 'M'};  //leds name

//using the Led class object constructor:
Led myLed[6](display);  //instatiate 3 leds passing the display object address to each one

void setup() {
  Serial.begin(9600);
  // initialize and clear display
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.clearDisplay();
  display.setTextColor(WHITE);

  // First line
  int j = 0;
  for(int i=0;i<ledsNumber;i++)
  {
    if (i == break_line && j == 0) {
      ++j; // Change Y value to draw two lines
    }

    myLed[i].centerX=centerX[i % 3]; // Reuse x positions
    myLed[i].centerY = centerY[j];
    myLed[i].name=name[i];
    myLed[i].Init();
  }
}

void loop() {
  for(int i=0;i<ledsNumber;i++)
  {
    myLed[i].LedOn();         //each led lights up
  }  
  display.display();         
  delay(500);
  for(int i=0;i<ledsNumber;i++)
  {
    myLed[i].LedOff();       //each led goes off
  }    
  display.display();
  delay(500);
}