Guest User

Untitled

a guest
Oct 29th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. #include "FastLED.h"
  2. #define DATA_PIN 2
  3. //#define CLK_PIN 4
  4. #define LED_TYPE WS2811
  5. #define COLOR_ORDER GRB
  6. #define NUM_LEDS 40
  7. CRGB leds[NUM_LEDS];
  8. #define BUTTON_LEAD 3
  9. #define BRIGHTNESS 96
  10. #define FRAMES_PER_SECOND 120
  11.  
  12. #define SPEED 50 //higher value is slower
  13. int showMode;
  14. //int pos = 0;
  15. //int posDir = 1;
  16. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  17.  
  18. void setup() {
  19. delay(3000); // 3 second delay for recovery
  20. Serial.begin(9600);
  21. // tell FastLED about the LED strip configuration
  22. FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  23. // set master brightness control
  24. FastLED.setBrightness(BRIGHTNESS);
  25. attachInterrupt(1, buttonListener, RISING);
  26. }
  27.  
  28. void loop() {
  29. line();
  30. EVERY_N_MILLISECONDS( 10 ) {
  31. gHue++; /* slowly cycle the "base color" through the rainbow*/
  32. }
  33. }
  34.  
  35. void line() {
  36. Serial.print ("start showMode = ");
  37. Serial.println (showMode);
  38. if (showMode == false) {
  39. for (int pos = 0; pos <= NUM_LEDS - 1; pos++) {
  40. Serial.print (pos);
  41. Serial.print (" , ");
  42. // Serial.println (posDir);
  43. FastLED.clear();
  44. leds[pos] += CHSV(gHue, 255, 255); //Center
  45. if (pos < NUM_LEDS) {
  46. leds[pos + 1] += CHSV(gHue, 255, 100); /*Leading edge of dot will be dimmed*/
  47. }
  48. if (pos > 1) {
  49. leds[pos - 1] += CHSV(gHue, 255, 100); /*if pos is zero do not send a negetive number to (leds)*/
  50. }
  51. Serial.print ("cntup showMode = ");
  52. Serial.println (showMode);
  53. FastLED.show();
  54. FastLED.delay(SPEED);
  55. }
  56. for (int pos = NUM_LEDS - 1; pos > 0; pos--) {
  57. Serial.print (pos);
  58. Serial.print (" , ");
  59. // Serial.println (posDir);
  60. FastLED.clear();
  61. leds[pos] += CHSV(gHue, 255, 255); /*Center*/
  62. if (pos < NUM_LEDS) {
  63. leds[pos + 1] += CHSV(gHue, 255, 100); /*Leading edge of dot will be dimmed*/
  64. }
  65. if (pos > 1) {
  66. leds[pos - 1] += CHSV(gHue, 255, 100); /*if pos is zero do not send a negetive number to (leds)*/
  67. }
  68. Serial.print ("cntdn showMode = ");
  69. Serial.println (showMode);
  70. FastLED.show();
  71. FastLED.delay(SPEED);
  72.  
  73. }
  74. }
  75. if (showMode == true) {
  76. wipe();
  77. Serial.println ("wipe");
  78. }
  79.  
  80. }
  81.  
  82. void wipe() {
  83. fadeToBlackBy(leds, NUM_LEDS, 15);
  84. FastLED.show();
  85. }
  86.  
  87. /* monitor button press */
  88. void buttonListener() {
  89. delay(20); /*Reccomend a hardware debounce to ensure flawless response*/
  90. if (digitalRead(3) == true) {
  91. showMode = !showMode;
  92. Serial.print ("Button Press showMode = ");
  93. Serial.println (showMode);
  94. }
  95. }
  96.  
  97. <----------SERIAL MONITOR OUTPUT----->
  98. start showMode = 0
  99. 0 , cntup showMode = 0
  100. 1 , cntup showMode = 0
  101. 2 , cntup showMode = 0
  102. 3 , cntup showMode = 0
  103. 4 , cntup showMode = 0
  104. 5 , cntup showMode = 0
  105. 6 , cntup showMode = 0
  106. 7 , cntup showMode = 0
  107. 8 , cntup showMode = 0
  108. 9 , cntup showMode = 0
  109. 10 , cntup showMode = 0
  110. 11 , cntup showMode = 0
  111. 12 , cntup showMode = 0
  112. 13 , cntup showMode = 0
  113. 14 , cntup showMode = 0
  114. 15 , cntup showMode = 0
  115. 16 , cntup showMode = 0
  116. 17 , cntup showMode = 0
  117. 18 , cntup showMode = 0
  118. 19 , cntup showMode = 0
  119. 20 , cntup showMode = 0
  120. 21 , cntup showMode = 0
  121. 22 , cntup showMode = 0
  122. 23 , cntup showMode = 0
  123. 24 , cntup showMode = 0
  124. 25 , cntup showMode = 0
  125. 26 , cntup showMode = 0
  126. 27 , cntup showMode = 0
  127. 28 , cntup showMode = 0
  128. 29 , cntup showMode = 0
  129. 30 , cntup showMode = 0
  130. 31 , cntup showMode = 0
  131. 32 , cntup showMode = 0
  132. 33 , cntup showMode = 0
  133. 34 , cntup showMode = 0
  134. 35 , cntup showMode = 0
  135. 36 , cntup showMode = 0
  136. 37 , cntup showMode = 0
  137. 38 , cntup showMode = 0
  138. 39 , cntup showMode = 40
  139. 39 , cntdn showMode = 80
  140. 38 , cntdn showMode = 80
  141. 37 , cntdn showMode = 80
  142. 36 , cntdn showMode = 80
  143. 35 , cntdn showMode = 80
  144. 34 , cntdn showMode = 80
  145. 33 , cntdn showMode = 80
  146. 32 , cntdn showMode = 80
  147. 31 , cntdn showMode = 80
  148. 30 , cntdn showMode = 80
  149. 29 , cntdn showMode = 80
  150. 28 , cntdn showMode = 80
  151. 27 , cntdn showMode = 80
  152. 26 , cntdn showMode = 80
  153. 25 , cntdn showMode = 80
  154. 24 , cntdn showMode = 80
  155. 23 , cntdn showMode = 80
  156. 22 , cntdn showMode = 80
  157. 21 , cntdn showMode = 80
  158. 20 , cntdn showMode = 80
  159. 19 , cntdn showMode = 80
  160. 18 , cntdn showMode = 80
  161. 17 , cntdn showMode = 80
  162. 16 , cntdn showMode = 80
  163. 15 , cntdn showMode = 80
  164. 14 , cntdn showMode = 80
  165. 13 , cntdn showMode = 80
  166. 12 , cntdn showMode = 80
  167. 11 , cntdn showMode = 80
  168. 10 , cntdn showMode = 80
  169. 9 , cntdn showMode = 80
  170. 8 , cntdn showMode = 80
  171. 7 , cntdn showMode = 80
  172. 6 , cntdn showMode = 80
  173. 5 , cntdn showMode = 80
  174. 4 , cntdn showMode = 80
  175. 3 , cntdn showMode = 80
  176. 2 , cntdn showMode = 80
  177. 1 , cntdn showMode = 80
  178. start showMode = 80
  179. start showMode = 80
  180. start showMode = 80
  181. start showMode = 80
  182. start showMode = 80
Advertisement
Add Comment
Please, Sign In to add comment