//https://github.com/Jestriker/police-lights-arduino
#define t 30
#define t1 20
#define t2 100
#define t3 50
//#define numLeds 12
int leds[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int outLeds[] = {2, 3, 4, 11, 12, 13};
int innerLeds[] = {5, 6, 7, 8, 9, 10};
// https://www.arduino.cc/reference/en/language/variables/utilities/sizeof/
// sizeof(); https://forum.arduino.cc/t/how-do-you-check-the-length-of-an-array/88325/7
int numLeds = sizeof(leds)/sizeof(int);
void setup() {
for (int i = 0; i < numLeds; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop1() {
animation_14(20);
test(15);
effect_10();
}
void loop() {
animation_1();
animation_1();
animation_2();
animation_2();
animation_3();
animation_3();
animation_4(500);
animation_4(500);
animation_4(500);
animation_4(500);
animation_5();
animation_5();
animation_5();
animation_7();
animation_7();
animation_7();
animation_7();
animation_8();
animation_8();
animation_8();
animation_9();
animation_9();
animation_9();
animation_9();
animation_10();
animation_10();
animation_10();
animation_10();
animation_10();
animation_10();
animation_10();
animation_11();
animation_11();
animation_11();
animation_11();
animation_12();
animation_12();
animation_12();
animation_12();
animation_13();
animation_13();
animation_13();
animation_14(20);
animation_14(20);
}
void test(const int dTime) {
//clear();
for (int i = numLeds - 1; i >= 0; i--) {
for (int k = i; k >= 0; k--) {
digitalWrite(leds[k], HIGH);
delay(dTime);
digitalWrite(leds[k], LOW);
delay(dTime);
}
digitalWrite(leds[i], HIGH);
delay(dTime);
}
}
void test3(const int dTime) {
//clear();
for (int i = numLeds - 1; i >= 0; i--) {
for (int k = i; k >= 0; k--) {
digitalWrite(leds[k], HIGH);
delay(dTime);
digitalWrite(leds[k], LOW);
delay(dTime);
}
digitalWrite(leds[i], HIGH);
delay(dTime);
}
for (int i = 0; i < 20; i++) {
allLedsOn(0, numLeds);
delay(30);
allLedsOff(0, numLeds);
delay(30);
}
}
void effect_10() {
for (int i = numLeds - 1; i >= 0; i--) {
for (int k = 0; k < i; k++) {
digitalWrite(leds[k], HIGH);
delay(20);
digitalWrite(leds[k], LOW);
delay(10);
}
digitalWrite(leds[i], HIGH);
delay(20);
}
}
void test2(const int dTime) {
for (int i = numLeds - 1; i >= 0; i--) {
digitalWrite(leds[numLeds - i], HIGH);
delay(10);
for (int k = numLeds - 1; k >= 0; k--) {
digitalWrite(leds[k - i], HIGH);
delay(10);
digitalWrite(leds[k - i], LOW);
delay(10);
}
}
}
void test1(const int dTime) {
for (int i = numLeds - 1; i >= 0; i--) {
if (i >= 0) {
digitalWrite(leds[i], HIGH);
delay(30);
digitalWrite(leds[i], LOW);
delay(30);
}
}
}
/////////////////////////////////////animation_1///////////////////////////////////////
void animation_1() {
clear();
for (int i = 0; i < numLeds; i++) {
digitalWrite(leds[i], HIGH);
delay(50);
digitalWrite(leds[i], LOW);
}
for (int i = numLeds - 1; i >= 0; i--) {
digitalWrite(leds[i], HIGH);
delay(50);
digitalWrite(leds[i], LOW);
}
}
/////////////////////////////////////animation_2///////////////////////////////////////
void animation_2() {
int count = 13;
for (int i = 0; i < numLeds; i++) {
clear();
digitalWrite(leds[i], HIGH); // chaser 1
digitalWrite(count, HIGH); // chaser 2
count--;
if (count != 7) {
delay(70);
}
}
for (int i = numLeds - 1; i >= 0; i--) {
clear();
digitalWrite(leds[i], HIGH);
digitalWrite(count, HIGH);
count++;
if (count != 8) {
delay(70);
}
}
}
/////////////////////////////////////animation_3///////////////////////////////////////
void animation_3() {
clear();
for (int i = 0; i < numLeds; i++) {
digitalWrite(leds[i], HIGH);
delay(50);
}
for (int i = 0; i < numLeds; i++) {
digitalWrite(leds[i], LOW);
delay(50);
}
for (int i = 0; i < 8; i++) {
digitalWrite (13, HIGH);
delay(20);
digitalWrite (13, LOW);
delay(20);
}
for (int i = numLeds - 1; i >= 0; i--) {
digitalWrite(leds[i], HIGH);
delay(50);
}
for (int i = numLeds - 1; i >= 0; i--) {
digitalWrite(leds[i], LOW);
delay(50);
}
for (int i = 0; i < 8; i++) {
digitalWrite (2, HIGH);
delay(20);
digitalWrite (2, LOW);
delay(20);
}
}
/////////////////////////////////////animation_4///////////////////////////////////////
void animation_4(const int dTime) {
for (int i = 0; i < numLeds; i = i + 2) {
digitalWrite(leds[i], HIGH);
}
delay(dTime);
for (int i = 0; i < numLeds; i = i + 2) {
digitalWrite(leds[i], LOW);
}
delay(dTime);
for (int i = 1; i < numLeds; i = i + 2) {
digitalWrite(leds[i], HIGH);
}
delay(dTime);
for (int i = 1; i < numLeds; i = i + 2) {
digitalWrite(leds[i], LOW);
}
delay(dTime);
}
/////////////////////////////////////animation_5///////////////////////////////////////
void animation_5() {
for (int i = 0; i < 6; i++) {
digitalWrite(leds[i], HIGH);
digitalWrite(leds[numLeds - i - 1], HIGH);
delay(70);
}
for (int i = 0; i < 6; i++) {
digitalWrite(leds[i], LOW);
digitalWrite(leds[numLeds - i - 1], LOW);
delay(70);
}
for (int k = 0; k < 5; k++) {
allLedsOn(5, 7);
delay(110);
allLedsOff(5, 7);
delay(110);
}
}
/////////////////////////////////////animation_6///////////////////////////////////////
void animation_6() {
// nothing special lol.
}
/////////////////////////////////////animation_7///////////////////////////////////////
void animation_7() {
// nothing special lol.
}
/////////////////////////////////////animation_8///////////////////////////////////////
void animation_8() {
for (int i = 0; i < 3; i++) {
allLedsOn(0, 6);
delay(70);
allLedsOff(0, 6);
delay(70);
}
delay(500);
for (int i = 0; i < 3; i++) {
allLedsOn(6, 12);
delay(70);
allLedsOff(6, 12);
delay(70);
}
delay(500);
}
/////////////////////////////////////animation_9///////////////////////////////////////
void animation_9() {
allLedsOn(0, 6);
delay(70);
allLedsOff(0, 6);
delay(70);
delay(500);
allLedsOn(6, 12);
delay(70);
allLedsOff(6, 12);
delay(70);
delay(500);
}
////////////////////////////////////animation_10///////////////////////////////////////
void animation_10() {
allLedsOn(0, 6);
delay (100);
allLedsOff(0, 6);
delay (100);
allLedsOn(6, numLeds);
delay (100);
allLedsOff(6, numLeds);
delay (100);
}
////////////////////////////////////animation_11///////////////////////////////////////
void animation_11() {
allLedsOn(0, numLeds);
delay(500);
allLedsOff(0, numLeds);
delay(500);
}
////////////////////////////////////animation_12///////////////////////////////////////
void animation_12() {
for (int p = 0; p < 6; p++) {
for (int i = 0; i < 6; i++) {
digitalWrite(outLeds[i], HIGH);
}
delay(40);
for (int i = 0; i < 6; i++) {
digitalWrite(outLeds[i], LOW);
}
delay(40);
}
delay(400);
for (int p = 0; p < 6; p++) {
for (int i = 0; i < 6; i++) {
digitalWrite(innerLeds[i], HIGH);
}
delay(40);
for (int i = 0; i < 6; i++) {
digitalWrite(innerLeds[i], LOW);
}
delay(40);
}
delay(400);
}
////////////////////////////////////animation_13///////////////////////////////////////
void animation_13() {
for (int i = 0; i < 8; i++) {
digitalWrite(leds[i], HIGH);
delay(15);
}
delay(150);
for (int i = 8; i >= 0; i--) {
digitalWrite(leds[i], LOW);
delay(40);
}
for (int i = numLeds - 1; i >= 4; i--) {
digitalWrite(leds[i], HIGH);
delay(15);
}
delay(150);
for (int i = 4; i < numLeds; i++) {
digitalWrite(leds[i], LOW);
delay(40);
}
}
////////////////////////////////////animation_14///////////////////////////////////////
void animation_14(const int dTime) {
for (int i = numLeds - 1; i >= 0; i--) {
for (int k = i; k >= 0; k--) {
digitalWrite(leds[k], HIGH);
delay(dTime);
digitalWrite(leds[k], LOW);
delay(dTime);
}
digitalWrite(leds[i], HIGH);
delay(dTime);
}
for (int i = 0; i < 10; i++) {
allLedsOn(0, numLeds);
delay(50);
allLedsOff(0, numLeds);
delay(100);
}
}
///////////////////////////////////////////////////////////////////////////
void clear() {
for (int i = 0; i < numLeds; i++) {
digitalWrite(leds[i], LOW);
}
}
///////////////////////////////////////////////////////////////////////////
void allLedsOn(int startLed, int endLed) {
for (int i = startLed; i < endLed; i++) {
digitalWrite(leds[i], HIGH);
}
}
///////////////////////////////////////////////////////////////////////////
void allLedsOff(int startLed, int endLed) {
for (int i = startLed; i < endLed; i++) {
digitalWrite(leds[i], LOW);
}
}