void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop()
{
static unsigned long lastTime = 0;
static unsigned char phase = 0;
unsigned long now = millis();
int period = analogRead(A0);
period = map(period, 0, 1023, 83, 750);
if (now - lastTime < period) return;
lastTime = now;
// Serial.println(analogRead(A0));
switch (phase & 0x3) { // just use bottom two bits of the phase counter
case 0 :
digitalWrite(3, LOW);
digitalWrite(4, LOW);
break;
case 1 :
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
break;
case 2 :
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
break;
case 3 :
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
break;
}
phase++;
}