Guest User

Untitled

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