// Placeholders for the array index..easier track with inde belongs to which colour
#include <Button.h>
const int R = 0;
const int G = 1;
const int B = 2;
int redPin[3] = {2, 3, 4}; // arrays for the 3 colour pins
int greenPin[3] = {5, 6, 7};
int bluePin[3] = {8, 9, 10};
Button btnRed(11);
Button btnGreen(12);
Button btnBlue(13);
const int buttons[3] = {11, 12, 13}; // might as well do one of the buttons...
int buttonState[3] = {0, 0, 0}; //..and their states
#define R_POT A0
#define G_POT A1
#define B_POT A2
int light1;
int light2;
int light3;
void setup() {
  // put your setup code here, to run once:
  light1 = 0;
  light2 = 0;
  light3 = 0;
  Serial.begin(9600);
  for (int i = 0; i < 3; i++) { // loop through the arrays to set the modes
    pinMode(redPin[i], OUTPUT);
    digitalWrite(redPin[i],HIGH);
    pinMode(greenPin[i], OUTPUT);
    digitalWrite(greenPin[i],HIGH);
    pinMode(bluePin[i], OUTPUT);
    digitalWrite(bluePin[i],HIGH);
  }
  btnRed.begin();
  btnBlue.begin();
  btnGreen.begin();
}
void loop() {
  if (btnRed.pressed()) {
    changeLights(R); // Send the array index number for the function to use
  }
    if (btnGreen.pressed()) {
    changeLights(G);
  }
    if (btnBlue.pressed()) {
    changeLights(B);
  }
}
void changeLights(int pin) {
  int data = 0;
  int percentage = 0;
  // Because the LEDS are common anode(+), 0/LOW is on, so mapping must be reversed
   analogWrite(redPin[pin], map(analogRead(R_POT), 0, 1023, 254, 0));
   analogWrite(greenPin[pin], map(analogRead(G_POT), 0, 1023, 254, 0));
   analogWrite(bluePin[pin], map(analogRead(B_POT), 0, 1023, 254, 0));
}