OK i was on here the other day and asked for help with a problem " how to print voltage after reading it with an interrupt " well I was just trying out how to increment with an interrupt using same methods
as was explained to and I wrote this code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <avr/interrupt.h>
#include <util/delay.h>
LiquidCrystal_I2C lcd(0x3f, 20, 4);
int count = 0;
bool flag = 0;
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
lcd.print("COUNT=");
}
void loop()
{
DDRB = 0b00000000;
DDRD = 0b00000000;
PORTD |= (1 << PORTB0); // turn On the Pull-up PB0 is now an input with pull-up enabled
PORTD |= (1 << PORTD3); // turn On the Pull-up PD3 is now an input with pull-up enabled
EICRA = (1 << ISC11) | (0 << ISC10); // set INT1 to trigger on falling edge
EIMSK = (1 << INT1); // Turns on INT1
if (flag == 1) {
lcd.setCursor(0, 0);
lcd.print("COUNT=");
lcd.print(count);
flag = 0;
}
sei(); // turn on interrupts
}
//*************ISR************
ISR (INT1_vect)
{
flag = 1;
count++;
_delay_ms(300);
}
//*****END-OF-ISR**************
the code works great but I have a denouncing problem it works good sometimes and sometimes it adds
2 or 3 times in one press i have tried using a delay in the code..does not help any thoughts on this ?