Guys, I'm new to arduino and I'm with some doubts . I'm trying to make an interactive light without using the delay ( ) . I searched the internet a few ways to replace the use of it and saw some blogs talking about TimerOne.h library. My problem is this , in my setup () I initialize my timer to 10 seconds , if I stipulate that time , because I want the green LED light of car is lit with red LED lights for pedestrians during this time or until the pedestrian push button requesting to change the sign of the lights , that a range of 5 ~ 10 seconds . Only when this time expires or the button is pressed , I need to change the states of the LEDs and change the period of my interruption too, would be something like simulate a delay ( ) , so that other LEDs remain illuminated for a period and then I can change states again, and so on. When manipulating time . I 've used several functions that library , such as : restart () , start () , stop () , setPeriod ( ) , and could not get the results I quoted the above . If anyone can help me with some sample code that I can do this manipulation or any other help , I appreciate it.
If you're new to this, you may want to try something simpler. Then, when that works, try adding some additional functions. Based on what you've said here, it looks like you're trying to write the whole program at once. When you do that, it can be very difficult to figure out what isn't working.
It sounds like you're making a traffic light controller. I'll suggest that you try making it work like a simple automatic traffic light: turns red for a while, and then turns green for a while - you don't mention a yellow light, so I presume that you're not implementing one. If you can't make it work, you can post your code, describe what you expected, and describe what you it does instead. If you can make it work, then you can try to add another function, and, when you run into trouble, post code, a clear description of what you expect, and a clear description of what it does. When you post code, please make sure that you post something that compiles, so that others can load it straight into an Arduino and see how it works.
So far, you haven't told us much. Your description is hard to understand, and you don't show any code. It's difficult for anyone to offer any help.
As you get further into this project, you may find that it works well as a state machine. Here are a couple of references that discuss state machines:
- From Nick Gammon, Gammon Forum : Electronics : Microprocessors : State machines
- From Grumpy Mike, State Machine