Created
February 5, 2017 20:57
-
-
Save marmilicious/36ac26bf9a8f0966a0762ba22eff6e1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*************************************************************** | |
// Delayed duplicate pattern using timer experiment. | |
// | |
// This example displays a pattern on the first half of a strip | |
// (call it section A) and then the same pattern is displayed | |
// on the second half of the strip (section B) but it's start | |
// time is delayed by a specified amount of time. | |
// | |
// Marc Miller, Feb 2017 | |
//*************************************************************** | |
#include "FastLED.h" | |
#define DATA_PIN 11 | |
#define CLK_PIN 13 | |
#define LED_TYPE LPD8806 | |
#define COLOR_ORDER GRB | |
#define NUM_LEDS 32 | |
#define BRIGHTNESS 80 | |
CRGB leds[NUM_LEDS]; | |
#define TIME_DELAY 600 // Delay in milliseconds before starting section B | |
boolean patternStarted = 0; // Has pattern started? [1=true/0=false] | |
boolean counterTriggered = 0; // Has section A started? [1=true/0=false] | |
static CEveryNMilliseconds trigger(TIME_DELAY); // Create timer | |
//--------------------------------------------------------------- | |
void setup() { | |
Serial.begin(115200); // Allows serial monitor output (check baud rate) | |
delay(3000); // 3 second delay for recovery | |
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); | |
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); | |
FastLED.setBrightness(BRIGHTNESS); | |
Serial.println("Setup done."); Serial.println(" "); | |
} | |
//--------------------------------------------------------------- | |
void loop() { | |
EVERY_N_MILLISECONDS(100){ | |
//***Run section A stuff here*** | |
static uint8_t posA = 0; | |
leds[posA] = CHSV(88,255,255); | |
posA++; | |
if (posA == NUM_LEDS/2) { posA = 0; } | |
checkStatus(); | |
//***Run section B stuff here*** | |
if (patternStarted && counterTriggered) { | |
static uint8_t posB = NUM_LEDS/2; | |
leds[posB] = CHSV(33,255,255); | |
posB++; | |
if (posB == NUM_LEDS) { posB = NUM_LEDS/2; } | |
} | |
FastLED.show(); | |
for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(180); } | |
}//end every_n... | |
}//end main loop | |
//--------------------------------------------------------------- | |
void checkStatus() { | |
if (patternStarted == 0) { | |
patternStarted = 1; //set true after the first time it's run | |
trigger.reset(); //reset timer | |
} | |
if (trigger) { | |
counterTriggered = 1; | |
} | |
//Serial.print("Trigger in: "); Serial.print(trigger.getRemaining()); Serial.print("ms "); Serial.print(" counterTriggered: "); Serial.println(counterTriggered); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment