Guest User

Untitled

a guest
Aug 3rd, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.41 KB | None | 0 0
  1. #include <Button.h>
  2. #include <FastLED.h>
  3.  
  4. #define LED_PIN     11
  5. #define NUM_LEDS    3
  6. #define BRIGHTNESS  128
  7. #define LED_TYPE    WS2812B
  8. #define COLOR_ORDER GRB
  9. #define UPDATES_PER_SECOND 100
  10. #define PULLUP true        //To keep things simple, we use the Arduino's internal pullup resistor.
  11. #define INVERT true        //Since the pullup resistor will keep the pin high unless the
  12.                            //switch is closed, this is negative logic, i.e. a high state
  13.                            //means the button is NOT pressed. (Assuming a normally open switch.)
  14. #define DEBOUNCE_MS 20     //A debounce time of 20 milliseconds usually works well for tactile button switches.
  15.  
  16. #define BUTTON_PIN 10
  17. Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS);    //Declare the button
  18. boolean ledState;          //A variable that keeps the current LED status
  19.  
  20. CRGB leds[NUM_LEDS];
  21.  
  22. int showType = 0;
  23.  
  24. void rainbow(uint8_t wait)
  25. {
  26.  
  27.     uint16_t hue;
  28.     FastLED.clear();
  29.  
  30.     for(hue=10; hue<255*3; hue++)
  31.     {
  32.  
  33.         fill_rainbow( &(leds[0]), NUM_LEDS /*led count*/, hue /*starting hue*/);       
  34.         FastLED.show();
  35.         delay(wait);
  36.     }
  37.     return;
  38. }
  39.  
  40. void setup()
  41. {
  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. int lastState = 0;
  48. int currentState = 0;
  49. int p = 0;
  50.  
  51. void loop()
  52. {
  53.     myBtn.read();                    //Read the button
  54.  
  55.     if (myBtn.wasPressed()) {       //If the button was released, change the LED state
  56.   showType++;
  57. if (showType >5) showType=0;
  58. startShow(showType);
  59. }
  60. }
  61.  
  62.  void startShow(int i) {
  63.   switch(i){
  64.     case 0: leds[0] = CRGB::Red;
  65.             leds[1] = CRGB::Aqua;
  66.             leds[2] = CRGB::Aqua;
  67.             FastLED.show();
  68.             break;
  69.    
  70.     case 1: leds[0] = CRGB::LimeGreen;
  71.             leds[1] = CRGB::LimeGreen;
  72.             leds[2] = CRGB::LimeGreen;
  73.             FastLED.show();
  74.             break;
  75.            
  76.     case 2: leds[0] = CRGB::Purple;
  77.             leds[1] = CRGB::Purple;
  78.             leds[2] = CRGB::Purple;
  79.             FastLED.show();
  80.             break;
  81.    case 3: leds[0] = CRGB::DarkSlateBlue;
  82.             leds[1] = CRGB::DarkSlateBlue;
  83.             leds[2] = CRGB::DarkSlateBlue;
  84.             FastLED.show();
  85.             break;
  86.    case 4:  rainbow(10);
  87.    break;
  88.    case 5:  rainbow(40);
  89.    break;
  90.   }
  91.  }
Advertisement
Add Comment
Please, Sign In to add comment