#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27 ,16 ,2);
int button1=2;
int button2=3;
int button3=4;
int button4=5;
int sttspb1=0;
int sttspb2=0;
int sttspb3=0;
int sttspb4=0;
int counter = 0;
const int maxCounterValue = 24;
void setup() {
lcd.init();
lcd.backlight ();
pinMode (button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
lcd.setCursor(0,0);
lcd.print ("Reifani Anistya");
lcd.setCursor(0,1);
lcd.print("18 juni 2008");
delay (1500);
lcd.setCursor(0, 1);
lcd.print("Counter:");
lcd.print(counter);
lcd.print(" ");
}
void loop() {
if (digitalRead(button1) == HIGH) {
if (counter < 24) {
counter++;
updateCounter();
}
delay(200);
}
if (digitalRead(button2) ==HIGH) {
if (counter > 0) {
counter--;
updateCounter();
}
delay(200);
}
if (digitalRead(button3) == HIGH) {
for (counter = 0;counter <= 24; counter++) {
updateCounter();
delay(1000);
}
delay(200);
}
if (digitalRead(button4) == HIGH) {
for (counter = 24; counter >= 0; counter--) {
updateCounter();
delay(1000);
}
delay(200);
}
}
void updateCounter() {
lcd.setCursor(8, 1);
lcd.print(counter);
lcd.print(" ");
}