#include <FastLED.h>
//Configuracion Leds
#define NUM_LEDS 16
#define DATA_PIN 7
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define BRIGHTNESS 180
#define VOLTS 5
#define MAX_AMPS 500
CRGB leds[NUM_LEDS];
//Configuracion Pines
#define PINBOTONSTARTA 2
#define PINSWITCHA1 3
#define PINSWITCHA2 4
#define PINPOTA1 A0
#define PINPOTA2 A1
#define PINPOTA3 A2
#define PINBOTONSTARTB 8
#define PINSWITCHB1 9
#define PINSWITCHB2 10
#define PINPOTB1 A3
#define PINPOTB2 A4
#define PINPOTB3 A5
//Variables
int color[NUM_LEDS];
int readya = 0;
int readyb = 0;
int valorswitchA1 = 0;
int valorswitchA2 = 0;
int valorswitchB1 = 0;
int valorswitchB2 = 0;
int valorpotA1 = 0;
int valorpotA2 = 0;
int valorpotA3 = 0;
int valorpotB1 = 0;
int valorpotB2 = 0;
int valorpotB3 = 0;
int turno = 0;
int totalpuntos = 0;
//Colores
#define COLORBAJO CRGB::Blue
#define COLORALTO CRGB::Red
#define COLOROK CRGB::Green
#define COLORLISTO CRGB::Orange
void setup() {
//Serial.begin(9600);
//Seteo de Pines
pinMode(PINBOTONSTARTA, INPUT_PULLUP);
pinMode(PINBOTONSTARTB, INPUT_PULLUP);
pinMode(PINSWITCHA1, INPUT_PULLUP);
pinMode(PINSWITCHA2, INPUT_PULLUP);
pinMode(PINSWITCHB1, INPUT_PULLUP);
pinMode(PINSWITCHB2, INPUT_PULLUP);
pinMode(PINPOTA1, INPUT);
pinMode(PINPOTA2, INPUT);
pinMode(PINPOTA3, INPUT);
pinMode(PINPOTB1, INPUT);
pinMode(PINPOTB2, INPUT);
pinMode(PINPOTB3, INPUT);
//Seteo de Leds
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
limpiartira();
turno = 1;
delay(100);
}
void loop() {
while ((readya + readyb) != 2) {
controlvalores();
}
totalpuntos = 0;
controldatos();
prenderleds();
turno++;
readya = 0;
readyb = 0;
if (totalpuntos >= 5) {
delay(2000);
limpiartira();
totalpuntos = 0;
turno = 1;
}
if (turno >= 4) {
delay(1000);
limpiartira();
turno = 1;
}
}
void controlvalores() {
if (digitalRead(PINBOTONSTARTA) == 0) {
readya = !readya;
color[(12 + turno)] = readya;
prenderleds();
delay(200);
}
if (digitalRead(PINBOTONSTARTB) == 0) {
readyb = !readyb;
color[(9 + turno)] = readyb;
prenderleds();
delay(200);
}
valorswitchA1 = digitalRead(PINSWITCHA1);
valorswitchA2 = digitalRead(PINSWITCHA2);
valorswitchB1 = digitalRead(PINSWITCHB1);
valorswitchB2 = digitalRead(PINSWITCHB2);
valorpotA1 = map(analogRead(PINPOTA1), 0, 1024, 0, 5);
delay(100);
valorpotA2 = map(analogRead(PINPOTA2), 0, 1024, 0, 5);
delay(100);
valorpotA3 = map(analogRead(PINPOTA3), 0, 1024, 0, 5);
delay(100);
valorpotB1 = map(analogRead(PINPOTB1), 0, 1024, 0, 5);
delay(100);
valorpotB2 = map(analogRead(PINPOTB2), 0, 1024, 0, 5);
delay(100);
valorpotB3 = map(analogRead(PINPOTB3), 0, 1024, 0, 5);
delay(100);
}
void controldatos() {
if (valorswitchA1 == valorswitchB1) {
color[3] = 2;
color[8] = 2;
totalpuntos++;
}
else {
color[3] = 4;
color[8] = 4;
}
if (valorswitchA2 == valorswitchB2) {
color[4] = 2;
color[9] = 2;
totalpuntos++;
}
else {
color[4] = 4;
color[9] = 4;
}
if (valorpotA1 == valorpotB1) {
color[0] = 2;
color[5] = 2;
totalpuntos++;
}
if (valorpotA1 > valorpotB1) {
color[0] = 4;
color[5] = 3;
}
if (valorpotA1 < valorpotB1) {
color[0] = 3;
color[5] = 4;
}
if (valorpotA2 == valorpotB2) {
color[1] = 2;
color[6] = 2;
totalpuntos++;
}
if (valorpotA2 > valorpotB2) {
color[1] = 4;
color[6] = 3;
}
if (valorpotA2 < valorpotB2) {
color[1] = 3;
color[6] = 4;
}
if (valorpotA3 == valorpotB3) {
color[2] = 2;
color[7] = 2;
totalpuntos++;
}
if (valorpotA3 > valorpotB3) {
color[2] = 4;
color[7] = 3;
}
if (valorpotA3 < valorpotB3) {
color[2] = 3;
color[7] = 4;
}
if (totalpuntos >= 5){
color[(12 + turno)] = 2;
color[(9 + turno)] = 2;
}
else {
color[(12 + turno)] = 4;
color[(9 + turno)] = 4;
}
}
void prenderleds() {
for (int i = 0; i < NUM_LEDS; i++) {
switch (color[i]) {
case 0:
leds[i] = CRGB::Black;
break;
case 1:
leds[i] = COLORLISTO;
break;
case 2:
leds[i] = COLOROK;
break;
case 3:
leds[i] = COLORBAJO;
break;
case 4:
leds[i] = COLORALTO;
break;
}
}
FastLED.show();
delay(1000);
}
void limpiartira() {
for (int i = 0; i < NUM_LEDS; i++) {
color[i] = 0;
}
FastLED.clear();
FastLED.show();
}