Author Topic: want a small c program  (Read 4283 times)

0 Members and 1 Guest are viewing this topic.

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
want a small c program
« 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

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: want a small c program
« Reply #1 on: July 25, 2007, 10:59:38 AM »
Im guessing that this is for a microcontroller? Which microcontroller? What compiler are you using?

Imperial College Robotics Society
www.icrobotics.co.uk

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: want a small c program
« Reply #2 on: July 25, 2007, 12:43:37 PM »
atmega16l
programmed with stk500 board
avr studio with the C plugin (avr gcc)

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: want a small c program
« Reply #3 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

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: want a small c program
« Reply #4 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;

 


Get Your Ad Here