// EMDR Therapy Tool
// v01 - Light is "moving" from LED to LED, speed can be adjusted with poti
// v02 - Brightness can also be adjusted with poti
// v03 - Using Poti as a hardware adjustable resistor instead of analogWrite for Brightness adjustment
// Light variables
int activeLED = 0;
int duration = 500;
int updown = 0; // 0 = Aufwrts laufen, 1 = abwrts
int minLED = 1;
unsigned long counterStart = millis();
int brightness = 255;
// Poti variables
int potiSpeed= A5;
int potiSpeedValue = 0;
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
// Serial.begin(9600); // For debugging, can be deactivated, observation: Calling Serial will enable TX/RX on PIN 0 and 1
}
void loop() {
// Read Speed Poti
potiSpeedValue = analogRead(potiSpeed);
duration = map(potiSpeedValue,0,1023,5,200); // So that the speed does not start at unreasonably low, and does not go up to 0 (=permanent)
// Serial.println(potiSpeedValue); // For debugging, can be deactivated
digitalWrite(activeLED, HIGH ); // Turn active LED on
counterStart = millis();
while (millis()-counterStart < duration) {
}
digitalWrite (activeLED, LOW); // Turn active LED off
if ((activeLED <=12) && (updown == 0)) {
activeLED++;
}
else if ((activeLED >= minLED) && (updown == 1)) {
activeLED--;
}
else if ((activeLED < minLED) && (updown == 1)) {
activeLED = minLED;
updown = 0;
}
else {
activeLED=12;
updown = 1;
}
}