Good afternoon,
I am trying to program a traffic light connected to a pressure sensor. My idea is that, when I press the sensor 1 time, green light turns on; when I press it 2 times, yellow light turns on, and finally, 3 times, red light.
For that, I have programmed this with XOD, but it is not working. Only the green light turns on, no matter how much pulses I give.
Can anyone tell me where is the mistake?
Thank you!
You probably don’t want the flip-flop here. The first time you press sensor, it turns flip-flop on and increments count to 1. The second time you press sensor, it turns flip-flop off, which doesn’t affect count. The third time you press sensor, it should turn flip-flop on and increment count to 2. Basically, you loose every second press of the sensor. You should be able to connect the greater node directly to the count node without the flip-flop.
I’m not sure why it NEVER turns on the yellow LED. That should happen on 3rd press. I do see that your current code only works for one cycle. When you have red LED on (count=3) and you increment counter again, it goes to 4, which doesn’t turn on any lights, then keeps increasing, which doesn’t turn on any lights. You could put a watch node on analog-sensor-VAL to monitor what is happening as you press the sensor. If it doesn’t drop below 0.006 when you release, that would prevent your code from seeing additional presses since it thinks it was never released.
It worked!! thank you so much!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.