Devices & Components
Arduino Uno Rev3
Breadboard (generic)
Rotary potentiometer (generic)
10mm LED Clip Holder
10mm Warm White LED
Resistor 330 ohm
Project description
Code
sfr_EMDR_v03.ino
arduino
Pins 0-13 are connected to LEDs. The code "moves" a light from one LED to the next. Potentiometers connected to steer brightness and speed of movement.
1 2 3// EMDR Therapy Tool 4// v01 - Light is "moving" from LED to LED, speed can be adjusted with poti 5// v02 - Brightness can also be adjusted with poti 6// v03 - Using Poti as a hardware adjustable resistor instead of analogWrite for Brightness adjustment 7 8 9 10// Light variables 11 12int activeLED = 0; 13int duration = 500; 14int updown = 0; // 0 = Aufwrts laufen, 1 = abwrts 15int minLED = 1; 16unsigned long counterStart = millis(); 17int brightness = 255; 18 19// Poti variables 20 21int potiSpeed= A5; 22int potiSpeedValue = 0; 23 24 25void setup() { 26 pinMode(13, OUTPUT); 27 pinMode(12, OUTPUT); 28 pinMode(11, OUTPUT); 29 pinMode(10, OUTPUT); 30 pinMode(9, OUTPUT); 31 pinMode(8, OUTPUT); 32 pinMode(7, OUTPUT); 33 pinMode(6, OUTPUT); 34 pinMode(5, OUTPUT); 35 pinMode(4, OUTPUT); 36 pinMode(3, OUTPUT); 37 pinMode(2, OUTPUT); 38 pinMode(1, OUTPUT); 39 pinMode(0, OUTPUT); 40 41 // Serial.begin(9600); // For debugging, can be deactivated, observation: Calling Serial will enable TX/RX on PIN 0 and 1 42} 43 44 45void loop() { 46 47 // Read Speed Poti 48 potiSpeedValue = analogRead(potiSpeed); 49 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) 50 // Serial.println(potiSpeedValue); // For debugging, can be deactivated 51 52 digitalWrite(activeLED, HIGH ); // Turn active LED on 53 54 counterStart = millis(); 55 56 while (millis()-counterStart < duration) { 57 } 58 59 digitalWrite (activeLED, LOW); // Turn active LED off 60 61 if ((activeLED <=12) && (updown == 0)) { 62 activeLED++; 63 64 } 65 66 else if ((activeLED >= minLED) && (updown == 1)) { 67 activeLED--; 68 } 69 70 else if ((activeLED < minLED) && (updown == 1)) { 71 activeLED = minLED; 72 updown = 0; 73 } 74 75 else { 76 activeLED=12; 77 updown = 1; 78 } 79 80} 81
Downloadable files
Schematic
Schematic

Comments
Only logged in users can leave comments