getting logical error in code

hello myself suyog
i am doing a project on vehicle congestion avoidance system

where i want to synchronize traffic signal with timer displaying on 16x2 lcd

for eg.
our led is changing from red to green and green to red after every 5 sec

and that 5 sec timer should be displayed on lcd like from 0-4 and from 4 it should go again to 0 and should continue in loop for eg 0,1,2,3,4,0,1,2,3,4,0,1,2,3,4…like this

we have 3 codes

onlyLED where LED glows sequentially after 5sec but the timer does not synchronize with led as it goes on continuing after 5 sec also like for eg 5,6,7,8,9,10…

so we introduced intterupt function in then timer go sequence but led does not change after every 5 seconds

finalcode.ino (2.85 KB)

onlyLED.ino (1.38 KB)

onlyTIMER.ino (1.44 KB)

First a tip, press Ctrl+T in the IDE, looks better, doesn't it?

Seconds tip, names like 'ledPin2' are pretty useless. You're talking about red and green leds, why not call it that? Or, at least use an array.

And what are you trying to do with interrupts and 'timer0_millis'? I see absolutely nothing that needs an interrupt.

suyog2521:
we have 3 codes

Which one would you like us to look at? Three seems a bit greedy.

Have a look at how millis() is used to manage timing in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

…R