Advertisement
Guest User

toEngels

a guest
Nov 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1.  
  2.  
  3. const int RED_PIN = 9;
  4. const int GREEN_PIN = 10;
  5. const int BLUE_PIN = 11;
  6.  
  7. int DISPLAY_TIME = 100; // In milliseconds
  8.  
  9.  
  10. void setup()
  11. {
  12. // Here we'll configure the Arduino pins we're using to
  13. // drive the LED to be outputs:
  14.  
  15. pinMode(RED_PIN, OUTPUT);
  16. pinMode(GREEN_PIN, OUTPUT);
  17. pinMode(BLUE_PIN, OUTPUT);
  18. }
  19.  
  20.  
  21. void loop()
  22. {
  23.  
  24.  
  25. mainColors();
  26.  
  27.  
  28.  
  29. // showSpectrum();
  30. }
  31.  
  32.  
  33.  
  34.  
  35. void mainColors()
  36. {
  37. // Green (turn just the green LED on):
  38.  
  39. digitalWrite(RED_PIN, LOW);
  40. digitalWrite(GREEN_PIN, HIGH);
  41. digitalWrite(BLUE_PIN, LOW);
  42.  
  43. delay(7000);
  44.  
  45.  
  46.  
  47. // Yellow (turn red and green on):
  48.  
  49. digitalWrite(RED_PIN, HIGH);
  50. digitalWrite(GREEN_PIN, HIGH);
  51. digitalWrite(BLUE_PIN, LOW);
  52.  
  53. delay(2000);
  54.  
  55. // Red (turn just the red LED on):
  56.  
  57. digitalWrite(RED_PIN, HIGH);
  58. digitalWrite(GREEN_PIN, LOW);
  59. digitalWrite(BLUE_PIN, LOW);
  60.  
  61. delay(5000);
  62.  
  63.  
  64.  
  65. }
  66.  
  67.  
  68. void showSpectrum()
  69. {
  70. int x; // define an integer variable called "x"
  71.  
  72. for (x = 0; x < 768; x++)
  73.  
  74. // Each time we loop (with a new value of x), do the following:
  75.  
  76. {
  77. showRGB(x); // Call RGBspectrum() with our new x
  78. delay(10); // Delay for 10 ms (1/100th of a second)
  79. }
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. void showRGB(int color)
  88. {
  89. int redIntensity;
  90. int greenIntensity;
  91. int blueIntensity;
  92.  
  93. // Here we'll use an "if / else" statement to determine which
  94. // of the three (R,G,B) zones x falls into. Each of these zones
  95. // spans 255 because analogWrite() wants a number from 0 to 255.
  96.  
  97. // In each of these zones, we'll calculate the brightness
  98. // for each of the red, green, and blue LEDs within the RGB LED.
  99.  
  100. if (color <= 255) // zone 1
  101. {
  102. redIntensity = 255 - color; // red goes from on to off
  103. greenIntensity = color; // green goes from off to on
  104. blueIntensity = 0; // blue is always off
  105. }
  106. else if (color <= 511) // zone 2
  107. {
  108. redIntensity = 0; // red is always off
  109. greenIntensity = 255 - (color - 256); // green on to off
  110. blueIntensity = (color - 256); // blue off to on
  111. }
  112. else // color >= 512 // zone 3
  113. {
  114. redIntensity = (color - 512); // red off to on
  115. greenIntensity = 0; // green is always off
  116. blueIntensity = 255 - (color - 512); // blue on to off
  117. }
  118.  
  119. // Now that the brightness values have been set, command the LED
  120. // to those values
  121.  
  122. analogWrite(RED_PIN, redIntensity);
  123. analogWrite(BLUE_PIN, blueIntensity);
  124. analogWrite(GREEN_PIN, greenIntensity);
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement