Last active
December 30, 2015 02:19
-
-
Save BorisKourt/7762237 to your computer and use it in GitHub Desktop.
This is described on my blog: http://boriskourt.com/2013/12/03/wraithguard/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// eltests.ino | |
unsigned long currentMillis = 0; | |
unsigned int seed = 10; | |
unsigned int flickerVariability = 700; | |
long previousMillis = 0; | |
long prevSeed = 0; | |
long prevFlick1 = 0; | |
long prevFlick2 = 0; | |
long prevFlick3 = 0; | |
long interval = 250; | |
long flickInterval = 700; | |
long seedInterval = 100; | |
int xVal = 0; | |
int yVal = 0; | |
int zVal = 0; | |
int mode = 1; | |
const int xPin = A3; | |
const int yPin = A4; | |
const int zPin = A5; | |
const int wire = 2; | |
const int pannel = 3; | |
const int ribbon = 4; | |
int ribbonStat = HIGH; | |
int wireStat = HIGH; | |
int pannelStat = HIGH; | |
int seedHigh = 0; | |
int seedLow = 9999; | |
void setup() { | |
pinMode(wire,OUTPUT); | |
pinMode(pannel,OUTPUT); | |
pinMode(ribbon,OUTPUT); | |
digitalWrite(wire,HIGH); | |
digitalWrite(pannel,HIGH); | |
digitalWrite(ribbon,HIGH); | |
} | |
void loop() { | |
currentMillis = millis(); | |
if(currentMillis - previousMillis > interval) { | |
previousMillis = currentMillis; | |
xVal = analogRead(xPin); | |
yVal = analogRead(yPin); | |
zVal = analogRead(zPin); | |
randomSeed(seed); | |
seed = (xVal + yVal + zVal) / 3; | |
if(seedHigh < seed) { | |
seedHigh = seed; | |
} | |
if (seedLow > seed) { | |
seedLow = seed; | |
} | |
if (xVal >= yVal && xVal >= zVal) { | |
mode = 1; | |
} else if (yVal >= xVal && yVal >= zVal) { | |
mode = 2; | |
} else if (zVal >= xVal && zVal >= yVal) { | |
mode = 3; | |
} else { | |
mode = 4; | |
} | |
} | |
//unsigned int test = int(random(20, flickInterval)); | |
if(currentMillis - prevSeed > flickerVariability) { | |
prevSeed = currentMillis + flickerVariability; | |
flickInterval = map((random(seed/2, seed * 2)),seedLow / 2, seedHigh * 4, 300,4000); | |
} | |
switch (mode) { | |
case 1: | |
modeOne(); | |
break; | |
case 2: | |
modeTwo(); | |
break; | |
case 3: | |
modeThree(); | |
break; | |
case 4: | |
modeFour(); | |
break; | |
} | |
digitalWrite(wire,wireStat); | |
digitalWrite(pannel,pannelStat); | |
digitalWrite(ribbon,ribbonStat); | |
} | |
void modeOne() { | |
if(currentMillis - prevFlick1 > flickInterval) { | |
prevFlick1 = currentMillis + flickInterval; | |
if (wireStat == HIGH) { | |
wireStat = LOW; | |
pannelStat = HIGH; | |
} else { | |
wireStat = HIGH; | |
pannelStat = LOW; | |
} | |
} | |
ribbonStat = HIGH; | |
} | |
void modeTwo() { | |
if(currentMillis - prevFlick2 > flickInterval) { | |
prevFlick2 = currentMillis + flickInterval; | |
if (ribbonStat == HIGH) { | |
ribbonStat = LOW; | |
pannelStat = HIGH; | |
} else { | |
ribbonStat = HIGH; | |
pannelStat = LOW; | |
} | |
} | |
wireStat = HIGH; | |
} | |
void modeThree() { | |
if(currentMillis - prevFlick3 > flickInterval) { | |
prevFlick3 = currentMillis + flickInterval; | |
if (pannelStat == HIGH) { | |
pannelStat = LOW; | |
wireStat = HIGH; | |
} else { | |
pannelStat = HIGH; | |
wireStat = LOW; | |
} | |
} | |
ribbonStat = HIGH; | |
} | |
void modeFour() { | |
wireStat = HIGH; | |
pannelStat = HIGH; | |
ribbonStat = HIGH; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment