hey there - new to coding and arduino here
I was designing an RGB LED which I can control using values from 0-100 from the serial monitor.
1.Unfortunately it seems to be just throwing up weird values in the serial monitor like 48,52.. and ignoring what i'm inputting.
-
I was hoping on adding a fader to fade from one color to the next color with a delay once its been inputted. - ideas?
-
Is this the most effective way of doing this, any coding help would be appreciated.
Thanks for your time!
//setup our used ports (where we have the LEDs), put them in the right order!!! Which is RGB!
//Â Â Â Â Â Â RÂ GÂ B
int leds[] = {11,10,9};
//the values for our LEDs, in RGB order
//Â Â Â Â Â Â Â RÂ GÂ B
int values[] ={255,0,0};
int inByte;
//set here the delay (in milliseconds)
int delaySec = 100;
//setup function, runs only once when the board is initialized
void setup(){
 // initialize serial communication:
 Serial.begin(9600);
 //set our ports for output (so we have power to light up the LEDs)
 for (int i=0;i<3;i++){
  pinMode(leds[i], OUTPUT);
 }
}
void loop(){
 // Check to see if serial connection is open and if it is continue
 if (Serial.available() > 0) {
Â
 // Read the serial for an input between 0-100 and change to the appropriate LED colour.
  inByte = Serial.read();Â
Â
  if (inByte == 0){
  //White
  values[0] = 255;
  values[1] = 250;
  values[2] = 250;
  }
 Â
  if ((inByte > 0) && (inByte < 11)){
  //Red
  values[0] = 255;
  values[1] = 0;
  values[2] = 0;
  } Â
 Â
  if ((inByte > 10) && (inByte < 21)){
  //Pink
  values[0] = 255;
  values[1] = 192;
  values[2] = 203;
  }
 Â
  if ((inByte > 20) && (inByte < 31)){
  //Orange
  values[0] = 255;
  values[1] = 165;
  values[2] = 0;
  }
 Â
  if ((inByte > 30) && (inByte < 41)){
  //Goldenrod
  values[0] = 218;
  values[1] = 165;
  values[2] = 32;
  }
 Â
  if ((inByte > 40) && (inByte < 51)){
  //Yellow
  values[0] = 250;
  values[1] = 250;
  values[2] = 0;
  }
 Â
  if ((inByte > 50) && (inByte < 61)){
  //Green Yellow
  values[0] = 173;
  values[1] = 255;
  values[2] = 47;
  }
 Â
  if ((inByte > 60) && (inByte < 71)){
  //Green
  values[0] = 0;
  values[1] = 255;
  values[2] = 0;
  }
 Â
  if ((inByte > 70) && (inByte < 81)){
  //Aqua
  values[0] = 127;
  values[1] = 255;
  values[2] = 212;
  }
 Â
  if ((inByte > 80) && (inByte < 91)){
  //Blue
  values[0] = 0;
  values[1] = 0;
  values[2] = 255;Â
  }
 Â
  if ((inByte > 91) && (inByte < 101)){
  //Violet
  values[0] = 138;
  values[1] = 43;
  values[2] = 226;
  }
 Serial.println(inByte);Â
Â
  //change colors
 for (int i=0;i<3;i++){
  analogWrite(leds[i], values[i]);
  delay(delaySec);
 }
}
}