SHARE
TWEET

Arduino - LED ambient backlight

w0lfiesmith Dec 6th, 2012 1,915 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Developed by Rajarshi Roy
  2. int red, green, blue; //red, green and blue values
  3. int RedPin = 9; //Red pin 9 has a PWM
  4. int GreenPin = 11; //Green pin 10 has a PWM
  5. int BluePin = 10; //Blue pin 11 has a PWM
  6. void setup()
  7. {
  8.  
  9. Serial.begin(9600);
  10. //initial values (no significance)
  11. int red = 255;
  12. int blue = 255;
  13. int green = 255;
  14. }
  15.  
  16. void loop()
  17. {
  18.  
  19. //protocol expects data in format of 4 bytes
  20. //(xff) as a marker to ensure proper synchronization always
  21. //followed by red, green, blue bytes
  22. if (Serial.available()>=4) {
  23. if(Serial.read() == 0xff){
  24. red = Serial.read();
  25. green= Serial.read();
  26. blue = Serial.read();
  27. }
  28. }
  29. //finally control led brightness through pulse-width modulation
  30. analogWrite (RedPin, red);
  31. analogWrite (GreenPin, green);
  32. analogWrite (BluePin, blue);
  33. delay(10); //just to be safe
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top