/************************************************************
* Sketch per control per bluetooth d'un LED RGB.
* Data: 21/04/2021
* Autor: T.Salas (tsalas@iesportdalcudia.org)
***********************************************************/
String readStr = "";
char c;
int red = 0;
int green = 0;
int blue = 0;
void setup() {
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
}
void loop() {
if( Serial.available() > 0 ) {
c = char(Serial.read());
if( c == '*' ) {
Serial.println( readStr );
red = readStr.substring( 0, readStr.indexOf(',') ).toInt();
green = readStr.substring( readStr.indexOf(',')+1, readStr.indexOf(';') ).toInt();
blue = readStr.substring( readStr.indexOf(';')+1, readStr.length() ).toInt();
analogWrite( 9, red );
analogWrite( 6, green );
analogWrite( 5, blue );
readStr = "";
} else {
readStr += c;
}
}
}