lady_krizzie
- Aug 2, 2012
- 30
- Joined
- Aug 2, 2012
- Messages
- 30
I made code, that when you push the button it will count. But when you press it for a long time, it still increments and still counts.How can I make it such that if I press it even too long, it only counts once? Thank you very much in advance.
Code:
[#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
#include "lcd.h"
int main (void)
{
hw_lcd_init();
DDRB &= ~(1 << PINB0);
PORTB |= (1 << PINB0);
//int PRESSED = 0;
int COUNT = 0;
char buffer [16];
lcd_clrscr();
while(1) {
sprintf(buffer,"%d",COUNT);
lcd_puts_wrap(buffer);
if ((PINB & (1<<PINB0))){
//BUTTON IS NOT PUSH
}else{
//BUTTON IS PUSHED
COUNT=COUNT+1;
}
_delay_ms(100);
}
return 0;
}
Last edited by a moderator: