Skip to content

Instantly share code, notes, and snippets.

@jonasjohansson
Last active June 2, 2018 20:51
Show Gist options
  • Save jonasjohansson/dd69162f56f571e1a954b9f7a0c076ff to your computer and use it in GitHub Desktop.
Save jonasjohansson/dd69162f56f571e1a954b9f7a0c076ff to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#define DELAY 2000
#define NUM_FLASHES 30
bool strobing = false;
bool debug = true;
int pirState = LOW;
int powerPin = 6;
int lightAPin = 7;
int lightBPin = 8;
int inputPin = 2;
void setup() {
Serial.begin(9600);
pinMode(inputPin,INPUT);
pinMode(powerPin,OUTPUT);
pinMode(lightAPin,OUTPUT);
pinMode(lightBPin,OUTPUT);
digitalWrite(lightAPin,LOW);
digitalWrite(lightBPin,LOW);
digitalWrite(powerPin,HIGH);
turnOn();
}
void loop() {
if (!strobing){
int val = digitalRead(inputPin);
if (val == HIGH){
if (pirState == LOW){
if (debug) Serial.println("Motion detected!");
pirState = HIGH;
strobe();
}
} else {
if (pirState == HIGH){
if (debug) Serial.println("Motion ended!");
pirState = LOW;
}
}
}
}
void strobe(){
strobing = true;
delay(DELAY);
for (int i = 0; i < NUM_FLASHES; i++){
int j = (i/2)+1;
digitalWrite(lightAPin,HIGH);
digitalWrite(lightBPin,LOW);
delay(DELAY/j);
digitalWrite(lightAPin,LOW);
digitalWrite(lightBPin,HIGH);
delay(DELAY/j);
}
turnOff();
delay(DELAY);
strobing = false;
}
void turnOn(){
digitalWrite(lightAPin,HIGH);
digitalWrite(lightBPin,HIGH);
}
void turnOff(){
digitalWrite(lightAPin,LOW);
digitalWrite(lightBPin,LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment