Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define DATA_PIN 2
- //#define CLK_PIN 4
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- #define NUM_LEDS 40
- CRGB leds[NUM_LEDS];
- #define BUTTON_LEAD 3
- #define BRIGHTNESS 96
- #define FRAMES_PER_SECOND 120
- #define SPEED 50 //higher value is slower
- int showMode;
- //int pos = 0;
- //int posDir = 1;
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- void setup() {
- delay(3000); // 3 second delay for recovery
- Serial.begin(9600);
- // tell FastLED about the LED strip configuration
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- attachInterrupt(1, buttonListener, RISING);
- }
- void loop() {
- line();
- EVERY_N_MILLISECONDS( 10 ) {
- gHue++; /* slowly cycle the "base color" through the rainbow*/
- }
- }
- void line() {
- Serial.print ("start showMode = ");
- Serial.println (showMode);
- if (showMode == false) {
- for (int pos = 0; pos <= NUM_LEDS - 1; pos++) {
- Serial.print (pos);
- Serial.print (" , ");
- // Serial.println (posDir);
- FastLED.clear();
- leds[pos] += CHSV(gHue, 255, 255); //Center
- if (pos < NUM_LEDS) {
- leds[pos + 1] += CHSV(gHue, 255, 100); /*Leading edge of dot will be dimmed*/
- }
- if (pos > 1) {
- leds[pos - 1] += CHSV(gHue, 255, 100); /*if pos is zero do not send a negetive number to (leds)*/
- }
- Serial.print ("cntup showMode = ");
- Serial.println (showMode);
- FastLED.show();
- FastLED.delay(SPEED);
- }
- for (int pos = NUM_LEDS - 1; pos > 0; pos--) {
- Serial.print (pos);
- Serial.print (" , ");
- // Serial.println (posDir);
- FastLED.clear();
- leds[pos] += CHSV(gHue, 255, 255); /*Center*/
- if (pos < NUM_LEDS) {
- leds[pos + 1] += CHSV(gHue, 255, 100); /*Leading edge of dot will be dimmed*/
- }
- if (pos > 1) {
- leds[pos - 1] += CHSV(gHue, 255, 100); /*if pos is zero do not send a negetive number to (leds)*/
- }
- Serial.print ("cntdn showMode = ");
- Serial.println (showMode);
- FastLED.show();
- FastLED.delay(SPEED);
- }
- }
- if (showMode == true) {
- wipe();
- Serial.println ("wipe");
- }
- }
- void wipe() {
- fadeToBlackBy(leds, NUM_LEDS, 15);
- FastLED.show();
- }
- /* monitor button press */
- void buttonListener() {
- delay(20); /*Reccomend a hardware debounce to ensure flawless response*/
- if (digitalRead(3) == true) {
- showMode = !showMode;
- Serial.print ("Button Press showMode = ");
- Serial.println (showMode);
- }
- }
- <----------SERIAL MONITOR OUTPUT----->
- start showMode = 0
- 0 , cntup showMode = 0
- 1 , cntup showMode = 0
- 2 , cntup showMode = 0
- 3 , cntup showMode = 0
- 4 , cntup showMode = 0
- 5 , cntup showMode = 0
- 6 , cntup showMode = 0
- 7 , cntup showMode = 0
- 8 , cntup showMode = 0
- 9 , cntup showMode = 0
- 10 , cntup showMode = 0
- 11 , cntup showMode = 0
- 12 , cntup showMode = 0
- 13 , cntup showMode = 0
- 14 , cntup showMode = 0
- 15 , cntup showMode = 0
- 16 , cntup showMode = 0
- 17 , cntup showMode = 0
- 18 , cntup showMode = 0
- 19 , cntup showMode = 0
- 20 , cntup showMode = 0
- 21 , cntup showMode = 0
- 22 , cntup showMode = 0
- 23 , cntup showMode = 0
- 24 , cntup showMode = 0
- 25 , cntup showMode = 0
- 26 , cntup showMode = 0
- 27 , cntup showMode = 0
- 28 , cntup showMode = 0
- 29 , cntup showMode = 0
- 30 , cntup showMode = 0
- 31 , cntup showMode = 0
- 32 , cntup showMode = 0
- 33 , cntup showMode = 0
- 34 , cntup showMode = 0
- 35 , cntup showMode = 0
- 36 , cntup showMode = 0
- 37 , cntup showMode = 0
- 38 , cntup showMode = 0
- 39 , cntup showMode = 40
- 39 , cntdn showMode = 80
- 38 , cntdn showMode = 80
- 37 , cntdn showMode = 80
- 36 , cntdn showMode = 80
- 35 , cntdn showMode = 80
- 34 , cntdn showMode = 80
- 33 , cntdn showMode = 80
- 32 , cntdn showMode = 80
- 31 , cntdn showMode = 80
- 30 , cntdn showMode = 80
- 29 , cntdn showMode = 80
- 28 , cntdn showMode = 80
- 27 , cntdn showMode = 80
- 26 , cntdn showMode = 80
- 25 , cntdn showMode = 80
- 24 , cntdn showMode = 80
- 23 , cntdn showMode = 80
- 22 , cntdn showMode = 80
- 21 , cntdn showMode = 80
- 20 , cntdn showMode = 80
- 19 , cntdn showMode = 80
- 18 , cntdn showMode = 80
- 17 , cntdn showMode = 80
- 16 , cntdn showMode = 80
- 15 , cntdn showMode = 80
- 14 , cntdn showMode = 80
- 13 , cntdn showMode = 80
- 12 , cntdn showMode = 80
- 11 , cntdn showMode = 80
- 10 , cntdn showMode = 80
- 9 , cntdn showMode = 80
- 8 , cntdn showMode = 80
- 7 , cntdn showMode = 80
- 6 , cntdn showMode = 80
- 5 , cntdn showMode = 80
- 4 , cntdn showMode = 80
- 3 , cntdn showMode = 80
- 2 , cntdn showMode = 80
- 1 , cntdn showMode = 80
- start showMode = 80
- start showMode = 80
- start showMode = 80
- start showMode = 80
- start showMode = 80
Advertisement
Add Comment
Please, Sign In to add comment