I am new to AVR, but i have programmed PICs before, only this time i am doing everything in linux too so you'll guess that i am using avrdude...
My goal for this project is to change a bicolor LED's color depending on a certain state.
By default, the led is RED (if you make the connections right of course), then i want it to go to yellow (which is a quick change between green and red) while the user is holding the button down then on release, it will go to green, then the next time it will turn off.
So, to recap,
LED is red
While i hold the button down its gonna be yellow
When i release it will be green
While i hold the button down again its gonna be yellow
When i release it will be off
While i hold the button down again its gonna be yellow
When i release it will be red (and so on...)
In my actual code, everything works really well sometimes, but sometimes the led gets stuck at yellow and i have no clue why
Any ideas?
Code is on ideone : http://ideone.com/LI9gH
Thanks
I'm guessing you're simply seeing the random generator missing the button changes about 1/3rd of the time, because the debouncing is slightly off. Consider the time spent in different states:
That's your main loop. As you can see, it checks the button in two instants during about 15ms time; and it doesn't compare to the last value for which it updated state, only with the value 10ms prior. Release the button during the 5ms period of "yellow", and allumerAmbre will not reset until the next release that happens to fall in the 10ms period. Also, the yellow wound up 1/15 red, possibly not the mix you intended.