Guest User

Untitled

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