Code keeps repeating

I’m trying to program a traffic light, but the code for the else statements keep repeating and some of the LEDs won’t turn on or off when they’re supposed to. Ultrawest or north means ultrasonic sensor

{
turnLEDOn(greennorth);
turnLEDOn(greenwest);
while(1==1)
{

if     (SensorValue(ultrawest<10))

{
turnLEDOff(greennorth);
turnLEDOn(yellownorth);
wait(3);
turnLEDOff(yellownorth);
turnLEDOn(rednorth);
wait(0.5);
turnLEDOff(redwest);
turnLEDOn(greenwest);
}
}

if (SensorValue(ultranorth<10))

{
turnLEDOff(greenwest);
turnLEDOn(yellowwest);
wait(3);
turnLEDOff(yellowwest);
turnLEDOn(redwest);
wait(0.5);
turnLEDOff(rednorth);
turnLEDOn(greennorth);

}
}

For reference the plan was to have the traffic lights run through the else code if there was nothing close enough detected to the sensor, and if there was something close enough it would run the other code.

You don’t have any else statements, I only see if statements in the code that you posted.

Yea sorry I meant if

I think you might have to put the < 10 outside of the SensorValue(). Like this:

if (SensorValue(ultranorth) < 10)
2 Likes