Skip to content

Commit

Permalink
Added siren example
Browse files Browse the repository at this point in the history
  • Loading branch information
rac2030 committed Jun 16, 2018
1 parent dc0e92b commit 4f02684
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions firmware/examples/LED-Siren/.vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"board": "espressif:esp32:nina_w10",
"configuration": "UploadSpeed=115200",
"port": "/dev/ttyUSB0",
"sketch": "LED-Siren.ino"
}
21 changes: 21 additions & 0 deletions firmware/examples/LED-Siren/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/home/rac/Arduino/hardware/espressif/esp32/cores/esp32"
],
"browse": {
"limitSymbolsToIncludedHeaders": false,
"path": [
"/home/rac/Arduino/hardware/espressif/esp32/cores/esp32"
]
},
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
73 changes: 73 additions & 0 deletions firmware/examples/LED-Siren/LED-Siren.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* LED siren example for MakeZurich badge 2018
*/

#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 the array of leds
CRGB leds[NUM_LEDS];

void setup() {
Serial.begin(115200);
Serial.println("\n\nSiren example");
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}

void loop() {
siren();
ledOff();
delay(1000);
}

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++) {
showRedBlack(LONG_DELAY);
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 j = 0; j <= 5; j++) {
showRedBlack(SHORT_DELAY);
}
for(int j = 0; j <= 5; j++) {
showBlackBlue(SHORT_DELAY);
}
}

// This will flash quickly between both LEDs
for(int i = 0; i <= 30; i++) {
showRedBlack(SHORT_DELAY);
showBlackBlue(SHORT_DELAY);
}

}

void ledOff() {
leds[0] = CRGB::Black;
leds[1] = CRGB::Black;
FastLED.show();
}


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

void showBlackBlue(int delayTime) {
leds[0] = CRGB::Blue;
leds[1] = CRGB::Black;
FastLED.show();
delay(delayTime);
}
3 changes: 3 additions & 0 deletions firmware/examples/LED-Siren/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LED Siren example

Just flashes different patterns that mimik a US police siren with red and blue on the MakeZurich badge 2018

0 comments on commit 4f02684

Please sign in to comment.