/*#define D 400*/
void readDelay(unsigned int*);
void switchOff(void);
void switchon(byte);
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
}
unsigned int D;
void loop() {
readDelay(&D);
/* clear */
switchOff();
delay(D);
readDelay(&D);
/* sequence */
switchOn(0);
delay(D);
switchOn(1);
delay(D);
switchOn(2);
delay(D);
readDelay(&D);
/* All On */
switchOff();
delay(D);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
delay(D);
readDelay(&D);
/* sequence back */
switchOff();
delay(D);
switchOn(2);
delay(D);
switchOn(1);
delay(D);
switchOn(0);
delay(D);
}
void readDelay(unsigned int *del)
{
*del = map(analogRead(A3), 0, 1023, 50, 800);
}
void switchOff(void)
{
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
}
void switchOn(byte n)
{
switchOff();
digitalWrite(n, HIGH);
}