Hello I would like to change the color of my RGB LED by entering a rgb code (example: 250, 84, 72) in the serial monitor but I can not decode the information enter the monitor can you help me ?
Thank you for your help but here I can not cut the information in several variables.
For example:
Number entered: 240 52 140
redValue = 240;
greenValue = 52;
blueValue = 140;
I tried all afternoon but it did not succeed
ATOM_71:
I tried all afternoon but
...I didn't post my attempts.
We can't help with code we can't see.
I do not know how to do it but here is my current code :
const byte numChars = 2;
String donnee_Recu[numChars];
char valeurLED[3];
boolean newData = false;
const int ledRouge = 10;
const int ledVert = 9;
const int ledBleu = 8;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
void setup() {
Serial.begin(9600);
pinMode(ledRouge, OUTPUT);
pinMode(ledVert, OUTPUT);
pinMode(ledBleu, OUTPUT);
analogWrite(ledRouge, redValue);
analogWrite(ledVert, greenValue);
analogWrite(ledBleu, blueValue);
}
void loop() {
decodage();
showNewData();
ranger_tab();
}
void decodage(){
static byte num_tableaux = 0;
char marqueur_fin = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != marqueur_fin) {
donnee_Recu[num_tableaux] = rc;
num_tableaux++;
if (num_tableaux >= numChars){
num_tableaux = numChars -1;
}
}
else {
donnee_Recu[num_tableaux] = '\0';
num_tableaux = 0;
newData = true;
}
}
}
void showNewData(){
if (newData == true){
newData = false;
}
}
Do you realise that the forum has a francophone section?
You should use code tags, not quote tags when posting code.
const byte numChars = 2;
String donnee_Recu[numChars];
I can't see why you have two elements of String variables, when you want to input three values.
I'd drop Strings now, and use "atoi" and C-strings instead.