Thanks. Somehow code example No3 works correctly. I have used a library for timer and simplified code from the answer above.
#include <LiquidCrystal_I2C.h>
#include <millisDelay.h> // Timer
#define button_pd 6
LiquidCrystal_I2C lcd(0x27, 16, 2);
int k = 0;
int cnt = 0;
//uint8_t previous_state; // previous state of the button
millisDelay d;
void setup() {
pinMode(button_pd, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
void loop() {
uint8_t state = digitalRead(button_pd);
if (state == LOW)
d.start(300);
//previous_state = state;
if (d.justFinished()) {
cnt = cnt + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
}
Thanks. Somehow code example No3 works correctly. I have used a library for timer and simplified code from the answer above.
#include <LiquidCrystal_I2C.h>
#include <millisDelay.h> // Timer
#define button_pd 6
LiquidCrystal_I2C lcd(0x27, 16, 2);
int k = 0;
int cnt = 0;
uint8_t previous_state; // previous state of the button
millisDelay d;
void setup() {
pinMode(button_pd, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
void loop() {
uint8_t state = digitalRead(button_pd);
if (state == LOW)
d.start(300);
previous_state = state;
if (d.justFinished()) {
cnt = cnt + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
}
Thanks. Somehow code example No3 works correctly. I have used a library for timer and simplified code from the answer above.
#include <LiquidCrystal_I2C.h>
#include <millisDelay.h> // Timer
#define button_pd 6
LiquidCrystal_I2C lcd(0x27, 16, 2);
int k = 0;
int cnt = 0;
//uint8_t previous_state; // previous state of the button
millisDelay d;
void setup() {
pinMode(button_pd, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
void loop() {
uint8_t state = digitalRead(button_pd);
if (state == LOW)
d.start(300);
//previous_state = state;
if (d.justFinished()) {
cnt = cnt + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
}
Thanks. Somehow code example No3 works correctly. I have used a library for timer and simplified code from the answer above.
#include <LiquidCrystal_I2C.h>
#include <millisDelay.h> // Timer
#define button_pd 6
LiquidCrystal_I2C lcd(0x27, 16, 2);
int k = 0;
int cnt = 0;
uint8_t previous_state; // previous state of the button
millisDelay d;
void setup() {
pinMode(button_pd, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
void loop() {
uint8_t state = digitalRead(button_pd);
if (state == LOW)
d.start(300);
previous_state = state;
if (d.justFinished()) {
cnt = cnt + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(cnt);
}
}