Guest User

line test 2

a guest
Oct 12th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include "FastLED.h"
  2. #define NUM_LEDS 60
  3. CRGB leds[NUM_LEDS];
  4. #define PIN 2
  5. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  6. #define FRAMES_PER_SECOND 120
  7.  
  8. #define BUTTON_LEAD 4
  9. //#define BRIGHTNESS_BUTTON 19
  10.  
  11. bool buttonState = LOW;
  12. bool lastButtonState = LOW;
  13. int mode = 1; //Default mode is one.
  14.  
  15. void setup()
  16. {
  17. pinMode(BUTTON_LEAD, INPUT_PULLUP);
  18. FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  19. FastLED.show();
  20. }
  21.  
  22. void loop() {
  23. if(buttonListener()) { line();}
  24. EVERY_N_MILLISECONDS( 10 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  25. }
  26.  
  27. void line(){
  28. int LineSize = 4;
  29. for(int i = 0; i < NUM_LEDS-LineSize-2; i++) {
  30. FastLED.clear();
  31. leds[i] += CHSV(gHue, 255, 255);
  32. for(int j = 1; j <= LineSize; j++) {
  33. leds[i+j] += CHSV(gHue, 255, 255);
  34. }
  35. leds[i+LineSize+1] += CHSV(gHue, 255, 255);
  36. FastLED.show();
  37. FastLED.delay(1000/FRAMES_PER_SECOND);
  38. }
  39. wipe();
  40. }
  41.  
  42. void wipe(){
  43. for(int i=0; i<NUM_LEDS; i++){
  44. leds[i] = CRGB::Black;
  45. FastLED.show();
  46. }
  47. }
  48.  
  49.  
  50. /* monitor button press */
  51. bool buttonListener() {
  52. bool modeChanged = false;
  53.  
  54. buttonState = digitalRead(BUTTON_LEAD);
  55.  
  56. if (buttonState != lastButtonState) {
  57. if (buttonState == LOW) {
  58. mode++;
  59. modeChanged = true;
  60. delay(250); // Debounce delay. I checked the best parameter and 250 was it.
  61. }
  62. }
  63. lastButtonState = buttonState;
  64.  
  65. return modeChanged;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment