24-11-2014, 12:43 PM
Hola a todos,
Queria saber si con el siguiente codigo puedo enviar un color en HEX via bluetooth al arduino y que este los encienda de forma que los cuatro leds lo representen de la forma mas aproximada. Hay algun error en el?
Queria saber si con el siguiente codigo puedo enviar un color en HEX via bluetooth al arduino y que este los encienda de forma que los cuatro leds lo representen de la forma mas aproximada. Hay algun error en el?
Código:
/*
*/
#define RED OCR1A
#define GREEN OCR1B
#define BLUE OCR1C
#define WHITE OCR4A
int whitevalue;
void setup() {
// initialize serial:
Serial.begin(9600);
Serial.print("Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )");
Serial.print('\n');
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// do it again:
int white = Serial.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {
// print the three numbers in one string as hexadecimal:
Serial.print("Data Response : ");
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
Serial.println(white, HEX);
}
}
}