Guest User

Untitled

a guest
Feb 13th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. #include "FastLED.h"
  2. #include <Bounce2.h>
  3.  
  4. FASTLED_USING_NAMESPACE
  5.  
  6. #if FASTLED_VERSION < 3001000
  7. #error "Requires FastLED 3.1 or later; check github for latest code."
  8. #endif
  9.  
  10. #define DATA_PIN 3
  11. #define CLK_PIN 4
  12. #define LED_TYPE APA102
  13. #define COLOR_ORDER BGR
  14. #define NUM_LEDS 64
  15.  
  16. int sensorR = A0;
  17. int sensorG = A1;
  18. int sensorB = A2;
  19.  
  20.  
  21. //Buttons
  22. Bounce debouncer1 = Bounce();
  23. Bounce debouncer2 = Bounce();
  24.  
  25. #define BUTTON1PIN 8
  26. #define BUTTON2PIN 9
  27. byte BUTTON1COUNT = 0;
  28. byte BUTTON2COUNT = 0;
  29. int LASTBUTTON1STATE = LOW;
  30. int LASTBUTTON2STATE = LOW;
  31.  
  32.  
  33.  
  34. CRGB leds[NUM_LEDS];
  35.  
  36. #define BRIGHTNESS 150
  37. #define FRAMES_PER_SECOND 120
  38.  
  39. void setup() {
  40. delay(1000); // 3 second delay for recovery
  41.  
  42. // tell FastLED about the LED strip configuration
  43. //FastLED.addLeds<APA102, DATA_PIN, CLK_PIN, BGR>(leds, NUM_LEDS);
  44. //FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  45. FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  46.  
  47. // set master brightness control
  48. FastLED.setBrightness(BRIGHTNESS);
  49.  
  50. pinMode(BUTTON1PIN, INPUT); // Set Button Pin to Input Mode
  51. pinMode(BUTTON2PIN, INPUT); // Set Button Pin to Input Mode
  52.  
  53. // Debounce Setup
  54. debouncer1.attach(BUTTON1PIN);
  55. debouncer1.interval(5); // interval in ms
  56. debouncer2.attach(BUTTON2PIN);
  57. debouncer2.interval(5); // interval in ms
  58.  
  59.  
  60. Serial.begin(9600);
  61. }
  62.  
  63.  
  64.  
  65.  
  66. void loop()
  67. {
  68. // Call the current pattern function once, updating the 'leds' array
  69. int valR = analogRead(sensorR);
  70. valR = map(valR, 0, 1023, 0, 255);
  71. int valG = analogRead(sensorG);
  72. valG = map(valG, 0, 1023, 0, 255);
  73. int valB = analogRead(sensorB);
  74. valB = map(valB, 0, 1023, 0, 255);
  75. //Serial.print ("Sensor Value");
  76. //Serial.println (sensorValue);
  77. //if (sensorValue != oldValue)
  78. //{
  79.  
  80. ReadButton1();
  81. Serial.println(BUTTON1COUNT);
  82.  
  83. switch (BUTTON1COUNT) {
  84. case 0 :
  85. leds[62]=CRGB(valR,valG,valB);
  86. leds[61]=leds[62];
  87. leds[60]=leds[62];
  88. leds[1]=leds[62];
  89. leds[2]=leds[62];
  90. leds[3]=leds[62];
  91. FastLED.show();
  92. break;
  93. case 1 :
  94. leds[59]=CRGB(valR,valG,valB);
  95. leds[58]=leds[59];
  96. leds[57]=leds[59];
  97. leds[4]=leds[59];
  98. leds[5]=leds[59];
  99. leds[6]=leds[59];
  100. FastLED.show();
  101. break;
  102. case 2 :
  103. leds[56]=CRGB(valR,valG,valB);
  104. leds[55]=leds[56];
  105. leds[54]=leds[56];
  106. leds[7]=leds[56];
  107. leds[8]=leds[56];
  108. leds[9]=leds[56];
  109. FastLED.show();
  110. break;
  111. case 3 :
  112. leds[53]=CRGB(valR,valG,valB);
  113. leds[52]=leds[53];
  114. leds[51]=leds[53];
  115. leds[10]=leds[53];
  116. leds[11]=leds[53];
  117. leds[12]=leds[53];
  118. FastLED.show();
  119. //break;
  120. //case 4 :
  121. //leds[50,49,48,13,14,15]=CRGB(valR,valG,valB);
  122. //break;
  123. //case 5 :
  124. //leds[47,46,45,16,17,18]=CRGB(valR,valG,valB);
  125. //break;
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. //leds[44,43,43,19,20,21]=CRGB(valR,valG,valB);
  140.  
  141. //leds[41,40,39,22,23,24]=CRGB(valR,valG,valB);
  142.  
  143. //leds[38,37,36,25,26,27]=CRGB(valR,valG,valB);
  144.  
  145. //leds[35,34,33,28,29,30]=CRGB(valR,valG,valB);
  146.  
  147. //leds[62,61,60,1,2,3]=CRGB(valR,valG,valB);
  148.  
  149. //fill_solid( leds, 63, CRGB(valR,valG,valB));
  150. //fill_solid( leds, NUM_LEDS, CRGB(50,0,200));
  151. //fill_solid(leds, NUM_LEDS, CHSV(sensorValue,255,BRIGHTNESS));
  152.  
  153. // send the 'leds' array out to the actual LED strip
  154. //FastLED.show();
  155. //}
  156. //oldValue=sensorValue;
  157. // insert a delay to keep the framerate modest
  158. delay(100);
  159.  
  160. }
  161.  
  162. //void ReadDial() {
  163. //
  164. //}
  165. }
  166. void ReadButton1() { //maybe pass variable to pick button to read ?
  167.  
  168. debouncer1.update();
  169.  
  170. int BUTTON1STATE = debouncer1.read();
  171. //int BUTTON2STATE = debouncer2.read();
  172.  
  173. if (BUTTON1STATE != LASTBUTTON1STATE) {
  174. if (BUTTON1STATE == HIGH) {
  175. BUTTON1COUNT++;
  176. if (BUTTON1COUNT == 4) {
  177. BUTTON1COUNT=0;
  178. }
  179. //Serial.print("Button 1 ");
  180. // Serial.println(BUTTON1COUNT);
  181. }
  182. LASTBUTTON1STATE=BUTTON1STATE;
  183. //delay(50);
  184. }
  185. }
  186.  
  187. void ReadButton2() { //maybe pass variable to pick button to read ?
  188.  
  189. debouncer2.update();
  190.  
  191. int BUTTON2STATE = debouncer2.read();
  192.  
  193. if (BUTTON2STATE != LASTBUTTON2STATE) {
  194. if (BUTTON2STATE == HIGH) {
  195. BUTTON2COUNT++;
  196. if (BUTTON2COUNT == 5) {
  197. BUTTON2COUNT=0;
  198. }
  199. //Serial.print("Button 1 ");
  200. // Serial.println(BUTTON1COUNT);
  201. }
  202. LASTBUTTON2STATE=BUTTON2STATE;
  203. //delay(50);
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment