Advertisement
RealHero

Arduino 1.9

Jun 5th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #define RED_PIN 11
  2. #define BLUE_PIN 10
  3. #define GREEN_PIN 9
  4. #define DELTA 3
  5.  
  6. void setup(){
  7. pinMode(BLUE_PIN, OUTPUT);
  8. pinMode(RED_PIN, OUTPUT);
  9. pinMode(GREEN_PIN, OUTPUT);
  10. }
  11.  
  12. int blue = 0;
  13. boolean blueWasOn = false;
  14. int red = 0;
  15. boolean redWasOn = true;
  16. int green = 0;
  17. boolean greenWasOn = false;
  18.  
  19. void loop(){
  20. if(blue < 255 && !blueWasOn){
  21. Plus(blue, blueWasOn, BLUE_PIN, redWasOn);
  22. Minus(green, greenWasOn, GREEN_PIN);
  23. }
  24.  
  25. if(red < 255 && !redWasOn){
  26. Plus(red, redWasOn, RED_PIN, greenWasOn);
  27. Minus(blue, blueWasOn, BLUE_PIN);
  28. }
  29.  
  30. if(green < 255 && !greenWasOn){
  31. Plus(green, greenWasOn, GREEN_PIN, blueWasOn);
  32. Minus(red, redWasOn, RED_PIN);
  33. }
  34. }
  35.  
  36. void Plus(int &color, boolean &colorWasOn, int pin, boolean &prePreColorWasOn){
  37. color = constrain(color + DELTA, 0, 255);
  38. if(color >= 252){
  39. colorWasOn = !colorWasOn;
  40. color = 255;
  41. prePreColorWasOn = false;
  42. }
  43. analogWrite(pin, color);
  44. delay(25);
  45. }
  46.  
  47. void Minus(int &preColor, boolean &preColorWasOn, int prePin){
  48. preColor = constrain(preColor - DELTA, 0, 255);
  49. if(preColor <= 3){
  50. preColor = 0;
  51. preColorWasOn = true;
  52. }
  53. analogWrite(prePin, preColor);
  54. delay(25);
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement