Background LED changer program for interfacing via Serial to a RGB device.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arduino_LED_interface.ino 803B

12345678910111213141516171819202122232425262728293031323334
  1. //Developed by Rajarshi Roy
  2. int red, green, blue; //red, green and blue values
  3. int RedPin = 10; //Red: PWM pin 10
  4. int GreenPin = 9; //Green: PWM pin 11
  5. int BluePin = 11; //Blue: PWM pin 9
  6. void setup()
  7. {
  8. Serial.begin(9600);
  9. //initial values (no significance)
  10. int red = 255;
  11. int blue = 255;
  12. int green = 255;
  13. }
  14. void loop()
  15. {
  16. //protocol expects data in format of 4 bytes
  17. //(xff) as a marker to ensure proper synchronization always
  18. //followed by red, green, blue bytes
  19. if (Serial.available()>=4)
  20. {
  21. if(Serial.read() == 0xff)
  22. {
  23. red = Serial.read();
  24. green= Serial.read();
  25. blue = Serial.read();
  26. }
  27. }
  28. //finally control led brightness through pulse-width modulation
  29. analogWrite (RedPin, red);
  30. analogWrite (GreenPin, green);
  31. analogWrite (BluePin, blue);
  32. delay(10); //just to be safe
  33. }