Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************
- * Arduino Police Lights Strobe Example
- * James C4S / www.cmiyc.com
- *
- * How to make lights strobe like police lights using millis() (no delay)
- *
- * http://www.cmiyc.com/tutorials/arduino-example-police-lights-with-millis
- *******************************/
- #include <Adafruit_NeoPixel.h>
- #define PIN 6
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(40, PIN);
- // English for which LED to Strobe
- #define RED 0x0
- #define BLUE 0x1
- // Variable to track which LED is on
- byte whichLED = RED;
- // State variables for the LEDs
- byte Red_State = LOW;
- byte Blue_State = LOW;
- // Some delay values to change flashing behavior
- unsigned long switchDelay = 250;
- unsigned long strobeDelay = 50;
- // Seed the initial wait for the strobe effect
- unsigned long strobeWait = strobeDelay;
- // Variable to see when we should swtich LEDs
- unsigned long waitUntilSwitch = switchDelay; // seed initial wait
- int numberOfLED = 40;
- int block1Count = 20;
- int block2Count = 20;
- int block1[] = {0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27,32,33,34,35};
- int block2[] = {4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31,36,37,38,39};
- uint32_t red = strip.Color(255, 0, 0);
- uint32_t blue = strip.Color(0, 0, 255);
- uint32_t white = strip.Color(255, 255, 255);
- uint32_t black = strip.Color(0, 0, 0);
- void setup() {
- strip.begin();
- strip.setBrightness(50);
- strip.show(); // Initialize all pixels to 'off'
- }
- void loop() {
- if (Red_State == LOW) {
- wipe(block1Count, block1, black) ;
- } else {
- wipe(block1Count, block1, red) ;
- }
- if (Blue_State == LOW) {
- wipe(block2Count, block2, black) ;
- } else {
- wipe(block2Count, block2, blue) ;
- }
- strip.show();
- // Toggle back and forth between the two LEDs
- if ((long)(millis() - waitUntilSwitch)>=0) {
- // time is up!
- Red_State = LOW;
- Blue_State = LOW;
- whichLED = !whichLED; // toggle LED to strobe
- waitUntilSwitch += switchDelay;
- }
- // Create the stobing effect
- if ((long)(millis() - strobeWait)>=0) {
- if (whichLED == RED)
- Red_State = !Red_State;
- if (whichLED == BLUE)
- Blue_State = !Blue_State;
- strobeWait += strobeDelay;
- }
- }
- void wipe(int myCount, int myBlock[], uint32_t myColor) {
- for (int led = 0; led < myCount ; led++) {
- strip.setPixelColor(myBlock[led], myColor);
- }
- }
- void wipeAll(int myCount, uint32_t myColor) {
- for (int led = 0; led < myCount ; led++) {
- strip.setPixelColor(led, myColor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement