Hello all,
I am trying to use a DigiSpark along with three DC Relay boards from DigiStump to run a traffic light. I wrote the sketch without an input trigger to start the cycle. It works perfect. I cannot get the input trigger to work, no matter what I do the light test runs and then the light cycle starts without the input trigger.
int motionSensor = 2;
int redLight = 3;
int yellowLight = 4;
int greenLight = 5;
void setup()
{
pinMode(motionSensor, INPUT);
pinMode(redLight, OUTPUT);
pinMode(yellowLight, OUTPUT);
pinMode(greenLight, OUTPUT);
for (int Lighttest = 0; Lighttest < 4; Lighttest ++)
{
digitalWrite(redLight, HIGH);
digitalWrite(yellowLight, HIGH);
digitalWrite(greenLight, HIGH);
delay(500);
digitalWrite(redLight, LOW);
digitalWrite(yellowLight, LOW);
digitalWrite(greenLight, LOW);
delay(500);
}
}
void loop()
{
if (motionSensor == x?x )
{
digitalWrite(redLight, HIGH);
delay(3000);
digitalWrite(redLight, LOW);
digitalWrite(yellowLight, HIGH);
delay(1500);
digitalWrite(yellowLight, LOW);
digitalWrite(greenLight, HIGH);
delay(3000);
digitalWrite(greenLight, LOW);
}
else
{
digitalWrite(redLight, LOW);
digitalWrite(yellowLight, LOW);
digitalWrite(greenLight, LOW);
}
}
I have tried with the motionSensor == to HIGH and LOW. Is the sketch correct and my wiring wrong?
thank you,
Micheal