Sensing Key and controlling LED

Sensing a key and controlling an LED is an important but not so simple task for an AVR beginner. The algorithm to do this is:

Sense key toggle LED
Sense key toggle LED
  1. Sense the key continuously.
  2. If the key is pressed, i/o pin is LOW. If the key is not pressed, the corresponding i/o pin is HIGH.
  3. If the pin is LOW, wait for 20 mS to neglect the bouncing of the key. This is known as de-bouncing delay.
  4. Toggle the LED state by XORing it with the LED bit.
  5. Wait till the key is released.
  6. Go to step number 1 again.

Here is the keyled file for download.

%d bloggers like this: