Skip to content

Commit

Permalink
Fixed a bug that showed colors onlyon first led
Browse files Browse the repository at this point in the history
  • Loading branch information
rac2030 committed Jun 16, 2018
1 parent 4f02684 commit 548e71e
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions firmware/examples/LED-Siren/LED-Siren.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* LED siren example for MakeZurich badge 2018
*/

#define FASTLED_ALLOW_INTERRUPTS 0
#include "FastLED.h"

#define NUM_LEDS 2
#define DATA_PIN 27 // GPIO18

// Delays used inside siren algorithm
#define SHORT_DELAY 200
#define LONG_DELAY 1000
#define SHORT_DELAY 100
#define LONG_DELAY 500

// Define the array of leds
CRGB leds[NUM_LEDS];
Expand All @@ -22,30 +22,44 @@ void setup() {

void loop() {
siren();
Serial.println("Siren off");
ledOff();
delay(1000);
delay(5000);
}

void siren() {
// This will flash the leds 10 times from red to blue slowly (each on its side and the other off)
for(int i = 0; i <= 10; i++) {
// This will flash the leds 5 times from red to blue slowly (each on its side and the other off)
Serial.println("Long flash");
for(int i = 0; i <= 5; i++) {
Serial.print("RED---");
showRedBlack(LONG_DELAY);
Serial.print("BLUE---\n");
showBlackBlue(LONG_DELAY);
}

// This will flash each side multiple times fast but switch between the two with the same pace
for(int i = 0; i <= 10; i++) {
for(int i = 0; i <= 5; i++) {
for(int j = 0; j <= 5; j++) {
Serial.print("RED-");
showRedBlack(SHORT_DELAY);
ledOff();
delay(50);
}
for(int j = 0; j <= 5; j++) {
Serial.print("BLUE-");
showBlackBlue(SHORT_DELAY);
ledOff();
delay(50);
}
Serial.print("\n");
}

// This will flash quickly between both LEDs
Serial.println("Quick flash");
for(int i = 0; i <= 30; i++) {
Serial.print("RED-");
showRedBlack(SHORT_DELAY);
Serial.print("BLUE-\n");
showBlackBlue(SHORT_DELAY);
}

Expand All @@ -66,8 +80,8 @@ void showRedBlack(int delayTime) {
}

void showBlackBlue(int delayTime) {
leds[0] = CRGB::Blue;
leds[1] = CRGB::Black;
leds[0] = CRGB::Black;
leds[1] = CRGB::Blue;
FastLED.show();
delay(delayTime);
}

0 comments on commit 548e71e

Please sign in to comment.