Guest User

Simple 2-Mode Strip

a guest
Apr 12th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define NUM_LEDS 10
  4. #define DATA_PIN 12
  5. #define BUTTON_PIN  3
  6. #define POT_PIN A0
  7.  
  8. CRGB leds[NUM_LEDS];
  9.  
  10. int stripState = 0;
  11. int caseMax = 2;
  12. int buttonState = LOW;
  13. int lastButtonState = LOW;
  14. long lastDebounceTime = 0;
  15. int debounceDelay = 50;
  16. long modeTime;
  17. int modeDelay = 10000;
  18. int buttonReading;
  19.  
  20. void setup() {
  21.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  22.   pinMode(BUTTON_PIN, INPUT_PULLUP);
  23.   Serial.begin(9600);
  24. }
  25.  
  26. void loop() {
  27.  
  28.   buttonReading = digitalRead(BUTTON_PIN);
  29.   Serial.println(digitalRead(BUTTON_PIN));
  30.   /*
  31.     if (buttonReading != lastButtonState) {
  32.       lastDebounceTime = millis();
  33.     }
  34.     if ((millis() - lastDebounceTime) > debounceDelay) {
  35.       if (buttonReading != buttonState) {
  36.         buttonState = buttonReading;
  37.         if (buttonState == LOW) {
  38.           stripState = (stripState + 1) % caseMax;
  39.           modeTime = millis();
  40.         }
  41.       }
  42.     }
  43.     lastButtonState = buttonReading;
  44.   */
  45.   if (millis() > modeTime + modeDelay) {
  46.     modeTime = millis();
  47.     stripState = (stripState + 1) % caseMax;
  48.   }
  49.  
  50.   if (stripState == 0) {
  51.     for (int i = 0; i < NUM_LEDS; i++) {
  52.       leds[i] = CRGB::White;
  53.     }
  54.   }
  55.  
  56.   if (stripState == 1) {
  57.     for (int i = 0; i < NUM_LEDS; i++) {
  58.       leds[i] = CHSV(analogRead(POT_PIN), 255, 255);
  59.     }
  60.   }
  61.   FastLED.show();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment