Guest User

Untitled

a guest
Aug 7th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. #include <Button.h>
  2. #include <FastLED.h>
  3.  
  4. #define LED_PIN     11
  5. #define BUTTON_PIN 10
  6. #define NUM_LEDS    3
  7. #define BRIGHTNESS  128
  8. #define LED_TYPE    WS2812B
  9. #define COLOR_ORDER GRB
  10. #define UPDATES_PER_SECOND 100
  11. #define PULLUP true        //To keep things simple, we use the Arduino's internal pullup resistor.
  12. #define INVERT true        //Since the pullup resistor will keep the pin high unless the
  13.                            //switch is closed, this is negative logic, i.e. a high state
  14.                            //means the button is NOT pressed. (Assuming a normally open switch.)
  15. #define DEBOUNCE_MS 20     //A debounce time of 20 milliseconds usually works well for tactile button switches.
  16.  
  17.  
  18. Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS);    //Declare the button
  19. CRGB leds[NUM_LEDS];
  20.  
  21. int showType = 0;
  22. long pause = 20;
  23. unsigned long previousMillis = 0;
  24. unsigned long currentMillis = millis();
  25. uint8_t bow = 0;
  26. uint8_t hueTick = 0;
  27.  
  28. /* --------------EFFECTS---------------------------*/
  29.  
  30. void rainbow(int interval){
  31.  
  32.       fill_rainbow( &(leds[0]), NUM_LEDS, hueTick);
  33.       LEDS.show();
  34.       LEDS.delay(interval);
  35.       if (hueTick >255) {hueTick = 0;}
  36. }
  37. /* --------------EFFECTS---------------------------*/
  38.  
  39. void setup()
  40. {
  41.   Serial.begin(9600);
  42.    delay( 3000 ); // power-up safety delay
  43.    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  44.    FastLED.setBrightness(  BRIGHTNESS );
  45.  }
  46.  
  47. void loop()
  48.  {
  49.    hueTick++;
  50.     myBtn.read();                    //Read the button
  51.  
  52.     if (myBtn.wasPressed()) {       //If the button was released, change the LED state
  53.       showType++;
  54.       if (showType >6) {showType=0;}}
  55.  startShow(showType);
  56.   }
  57.  
  58.   void startShow(int i) {
  59.     switch(i){
  60.       case 0: leds[0] = CRGB::Red;
  61.       leds[1] = CRGB::Aqua;
  62.       leds[2] = CRGB::Aqua;
  63.       FastLED.show();
  64.       break;
  65.  
  66.       case 1: leds[0] = CRGB::LimeGreen;
  67.       leds[1] = CRGB::LimeGreen;
  68.       leds[2] = CRGB::LimeGreen;
  69.       FastLED.show();
  70.       break;
  71.  
  72.       case 2: leds[0] = CRGB::Purple;
  73.       leds[1] = CRGB::Purple;
  74.       leds[2] = CRGB::Purple;
  75.       FastLED.show();
  76.       break;
  77.       case 3: leds[0] = CRGB::DarkSlateBlue;
  78.       leds[1] = CRGB::DarkSlateBlue;
  79.       leds[2] = CRGB::DarkSlateBlue;
  80.       FastLED.show();
  81.       break;
  82.       case 4:  
  83.       rainbow(10);
  84.       break;
  85.       case 5:  
  86.       leds[0] = CRGB::Gray;
  87.       leds[1] = CRGB::Gray;
  88.       leds[2] = CRGB::Gray;
  89.       FastLED.show();
  90.       break;
  91.      case 6:  rainbow(40);
  92.             break;
  93.     }
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment