Society of Robots - Robot Forum

Software => Software => Topic started by: bakil on July 25, 2007, 10:47:11 AM

Title: want a small c program
Post by: bakil on July 25, 2007, 10:47:11 AM
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: [Select]

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

hope u understand my question

thks in advance ;D
Title: Re: want a small c program
Post by: hazzer123 on July 25, 2007, 10:59:38 AM
Im guessing that this is for a microcontroller? Which microcontroller? What compiler are you using?

Title: Re: want a small c program
Post by: bakil on July 25, 2007, 12:43:37 PM
atmega16l
programmed with stk500 board
avr studio with the C plugin (avr gcc)
Title: Re: want a small c program
Post by: bakil on July 27, 2007, 12:44:12 PM
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
Title: Re: want a small c program
Post by: Admin on July 31, 2007, 11:39:16 AM
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;