Software > Software

want a small c program

(1/1)

bakil:
hy today my question is that one of u guys can make a small c program that uses a little button and when you press the button i want a integer lets say a to be increased by one


like

--- Code: ---
main()
{
int a = 0;
if (button pushed)
{
a++;
}
}

--- End code ---

hope u understand my question

thks in advance ;D

hazzer123:
Im guessing that this is for a microcontroller? Which microcontroller? What compiler are you using?

bakil:
atmega16l
programmed with stk500 board
avr studio with the C plugin (avr gcc)

bakil:
i use a stk500 board (programmer and has LEDs and switches for testing)
avr studio and avr gcc

so how would u guys program somethin so that when u push a switch that an integer increments with one

Admin:
Make sure to put a small capacitor across both connections of your button for debouncing.

Then do something like:

if(button_pin = 1)
   counter=counter+1;

Navigation

[0] Message Index

Go to full version