#include <ezButton.h>

#define DEBOUNCE_TIME 20 // the debounce time in millisecond, increase this time if it still chatters

int LightSwitch = 0;

// Buttons
ezButton button1(2); // create ezButton object that attach to pin GIOP22

// LED 1
#define LED1_RED 12
#define LED1_GREEN 13
#define LED1_BLUE 14
// LED 2
#define LED2_RED 21
#define LED2_GREEN 22
#define LED2_BLUE 23

void setup() {
  button1.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 milliseconds
  // LED 1
  pinMode(LED1_RED, OUTPUT);
  pinMode(LED1_GREEN, OUTPUT);
  pinMode(LED1_BLUE, OUTPUT);
  // LED 2
  pinMode(LED2_RED, OUTPUT);
  pinMode(LED2_GREEN, OUTPUT);
  pinMode(LED2_BLUE, OUTPUT);
}

void loop() {

  button1.loop(); // MUST call the loop() function first

  if (button1.isReleased()) {
    if (LightSwitch == 0) {
      LightSwitch = 1;
    } else {
      LightSwitch = 0;
    }
  }
    
  if (LightSwitch == 0) {
    // LED1 on
    analogWrite(LED1_RED,   0);
    analogWrite(LED1_GREEN, 255);
    analogWrite(LED1_BLUE,  0);
    // LED2 off
    analogWrite(LED2_RED,   0);
    analogWrite(LED2_GREEN, 0);
    analogWrite(LED2_BLUE,  0);
  } else {
    // LED1 off
    analogWrite(LED1_RED,   0);
    analogWrite(LED1_GREEN, 0);
    analogWrite(LED1_BLUE,  0);
    // LED2 on
    analogWrite(LED2_RED,   0);
    analogWrite(LED2_GREEN, 255);
    analogWrite(LED2_BLUE,  0);
  }
  
  
    

}