Guest User

Untitled

a guest
Aug 3rd, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 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.   uint16_t hue;
  26.   FastLED.clear();
  27.  
  28. for(hue=10; hue<255*3; hue++) {
  29.     myBtn.read();
  30.     if (myBtn.wasPressed()) {       //If the button was pressed, change the LED state
  31.       showType++;
  32.       if (showType >5) {
  33.           showType=0;
  34.           startShow(showType);
  35. }
  36. }
  37.  
  38. else {
  39.   fill_rainbow( &(leds[0]), NUM_LEDS /*led count*/, hue /*starting hue*/);     
  40.   FastLED.show();
  41.   LEDS.delay(wait);
  42. }
  43. }
  44. }
  45.  
  46. void setup()
  47. {
  48.    delay( 3000 ); // power-up safety delay
  49.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  50.   FastLED.setBrightness(  BRIGHTNESS );
  51.   }
  52.  
  53. int lastState = 0;
  54. int currentState = 0;
  55. int p = 0;
  56.  
  57. void loop()
  58. {
  59.     myBtn.read();                    //Read the button
  60.  
  61.     if (myBtn.wasPressed()) {       //If the button was released, change the LED state
  62.   showType++;
  63. if (showType >5) showType=0;
  64. startShow(showType);
  65. }
  66. }
  67.  
  68.  void startShow(int i) {
  69.   switch(i){
  70.     case 0: leds[0] = CRGB::Red;
  71.             leds[1] = CRGB::Aqua;
  72.             leds[2] = CRGB::Aqua;
  73.             FastLED.show();
  74.             break;
  75.    
  76.     case 1: leds[0] = CRGB::LimeGreen;
  77.             leds[1] = CRGB::LimeGreen;
  78.             leds[2] = CRGB::LimeGreen;
  79.             FastLED.show();
  80.             break;
  81.            
  82.     case 2: leds[0] = CRGB::Purple;
  83.             leds[1] = CRGB::Purple;
  84.             leds[2] = CRGB::Purple;
  85.             FastLED.show();
  86.             break;
  87.    case 3: leds[0] = CRGB::DarkSlateBlue;
  88.             leds[1] = CRGB::DarkSlateBlue;
  89.             leds[2] = CRGB::DarkSlateBlue;
  90.             FastLED.show();
  91.             break;
  92.    case 4:  rainbow(30);
  93.    break;
  94.    case 5:  rainbow(40);
  95.    break;
  96.   }
  97.  }
Advertisement
Add Comment
Please, Sign In to add comment