/*************************************************** This is a library for the CAP1188 I2C/SPI 8-chan Capacitive Sensor
Designed specifically to work with the CAP1188 sensor from Adafruit ----> https://www.adafruit.com/products/1602
These sensors use I2C/SPI to communicate, 2+ pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution
****************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>

// Reset Pin is used for I2C or SPI
#define CAP1188_RESET 9

// CS pin is used for software or hardware SPI
#define CAP1188_CS 10

// These are defined for software SPI, for hardware SPI, check your board's SPI pins in the Arduino documentation
#define CAP1188_MOSI 11
#define CAP1188_MISO 12
#define CAP1188_CLK 13

// For I2C, connect SDA to your Arduino's SDA pin, SCL to SCL pin
// On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5
// On Leonardo/Micro, SDA == Digital 2, SCL == Digital 3
// On Mega/ADK/Due, SDA == Digital 20, SCL == Digital 21

// Use I2C, no reset pin!

Adafruit_CAP1188 cap = Adafruit_CAP1188();

// Or...Use I2C, with reset pin
//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_RESET);

// Or... Hardware SPI, CS pin & reset pin
// Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CS, CAP1188_RESET);

// Or.. Software SPI: clock, miso, mosi, cs, reset
//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CLK, CAP1188_MISO, CAP1188_MOSI, CAP1188_CS, CAP1188_RESET);

String red_input;
String blue_input;
String yellow_input;
String colors = "rby";
String secondary ="pog";
String random_color;
String selected_color;

//LED inputs
#define REDPIN 3
#define GREENPIN 5
#define BLUEPIN 6

#define randomHatStartNum 1 // starting number in hat
#define randomHatEndNum 3 // ending number in hat - end has to be larger than start
#define numberInHat (randomHatEndNum - randomHatStartNum) + 1

int score = 0;
bool result;

int FADESPEED = 50;
int HOLD = 1000;
int r_final = 255;
int b_final = 255;
int g_final = 255;



void setup() {
Serial.begin(9600);
Serial.println("CAP1188 test!");

// Initialize the sensor, if using i2c you can pass in the i2c address
if (!cap.begin(0x29)) {
Serial.println("Capacitar not found");
while (1);
}
Serial.println("Capacitar found!");
}

void loop() {
//initialize the colors
analogWrite(REDPIN, 255);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 255);

//pick color
int x = randomHat();
int i = 1;

if (score <){ //primary colors before team has scored 3 points
random_color = colors[x];
}
else{ //secondary colors after team has scored 3 points
random_color = secondary[x];
}

//selected color flashes
flashing(random_color);

//prepare checker
if (random_color =="p"){
random_color = "rb";
}
else if (random_color =="o"){
random_color = "ry";
}
else if (random_color =="g") {
random_color = "by";
}
else {}
//check if team is on correct color
bool result = checker();

//change score
if (result) { //scored point
score = score + 1;}
if (score == 5) { //win game
void rainbow();
score = 0;
}
else { //lose
score = 0;
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);}
delay(10000);
}