Advertisement
andretafta

Arduino RGB Smooth Transition

Mar 10th, 2025 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int red = 7
  2. const int green = 6
  3. const int blue = 5
  4.  
  5. int r = 255;
  6. int b; /* blue led value is temporally 0 */
  7. int g; /* green led value is temporally 0 */
  8.  
  9. int t = 1000;
  10.  
  11. void setup()
  12.  
  13.  
  14. void loop() {
  15.  
  16. for (/* no initialization */; r>=0, b<255; b++, r--) /*red -> blue*/
  17.  
  18. {
  19.  
  20. analogWrite(red, r);
  21.  
  22. analogWrite(blue, b);
  23.  
  24. delay(t);
  25.  
  26. }
  27.  
  28. for (/* no initialization */; b>=0, g<255; g++, b--) /*blue -> green*/
  29.  
  30. {
  31.  
  32. analogWrite(blue, b);
  33.  
  34. analogWrite(green, g);
  35.  
  36. delay(t);
  37.  
  38. }
  39.  
  40. for (/* no initialization */; g>=0, r<255; r++, g--) /*green -> red*/
  41.  
  42. {
  43.  
  44. analogWrite(red, r);
  45.  
  46. analogWrite(green, g);
  47.  
  48. delay(t);
  49.  
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement