tracciato-7.25/segnale-Icat-tondo/arduino-2vele/F-SIC/F-SIC.ino

143 lines
2.8 KiB
C++

#include <RGBLed.h>
#define RED0 3
#define GREEN0 5
#define BLU0 4
#define RED1 6
#define GREEN1 9
#define BLU1 7
RGBLed led0(RED0, GREEN0, BLU0, RGBLed::COMMON_ANODE);
RGBLed led1(RED1, GREEN1, BLU1, RGBLed::COMMON_ANODE);
char c;
void pulsed_state (void);
void serialFlush(void);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
led0.setColor(RGBLed::RED);
led1.off();
}
void loop() {
// put your main code here, to run repeatedly:
loop_start:
delay(1000);
if(!Serial.available()) goto loop_start;
c = Serial.read();
serialFlush();
led0.brightness(100);
led1.brightness(100);
switch (c){
case '0':
led0.off();
led1.off();
break;
case 'a':
led0.setColor(RGBLed::RED);
led1.off();
break;
case 'b':
led0.setColor(RGBLed::YELLOW);
led1.off();
break;
case 'c':
led0.setColor(RGBLed::GREEN);
led1.off();
break;
case 'd':
pulsed_state();
break;
case 'e':
led0.setColor(RGBLed::RED);
led1.setColor(150, 255, 0);
//led1.setColor(RGBLed::YELLOW);
break;
case 'f':
led0.setColor(RGBLed::RED);
led1.setColor(RGBLed::GREEN);
break;
case 'g':
pulsed_state();
break;
case 'h':
led0.setColor(RGBLed::YELLOW);
led1.setColor(150, 255, 0);
//led1.setColor(RGBLed::YELLOW);
break;
case 'i':
led0.setColor(RGBLed::YELLOW);
led1.setColor(RGBLed::GREEN);
break;
case 'j':
pulsed_state();
break;
case 'k':
pulsed_state();
break;
}
}
void pulsed_state (void){
do {
led0.brightness(100);
led1.brightness(100);
switch (c){
case 'd':
led0.setColor(RGBLed::YELLOW);
led1.off();
break;
case 'g':
led0.setColor(RGBLed::RED);
led1.setColor(150, 255, 0);
break;
case 'j':
led0.setColor(RGBLed::YELLOW);
led1.setColor(RGBLed::GREEN);
break;
case 'k':
led0.setColor(RGBLed::YELLOW);
led1.brightness(RGBLed::GREEN, 10);
break;
}
delay(1000);
led0.brightness(100);
led1.brightness(100);
switch (c){
case 'd':
led0.brightness(RGBLed::YELLOW, 10);
led1.off();
break;
case 'g':
led0.setColor(RGBLed::RED);
led1.brightness(150, 255, 0, 10);
break;
case 'j':
led0.brightness(RGBLed::YELLOW, 10);
led1.brightness(RGBLed::GREEN, 10);
break;
case 'k':
led0.brightness(RGBLed::YELLOW, 10);
led1.setColor(RGBLed::GREEN);
break;
}
delay(1000);
}
while (!Serial.available());
}
void serialFlush(void){
while(Serial.available() > 0) {
char t = Serial.read();
}
}