Arduino Button dan tampilan text I2C LCD
#include
#includeLiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int buttonPin = 2; // the number of the pushbutton pin
const int buttonPin1 = 3; // the number of the pushbutton pin
int buttonState = 0; // variables will change:
int buttonState1 = 1;
void setup()
{
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(“Isur dan Arduino”);
lcd.setCursor(0,1);
lcd.print(“BUTTON & LCD-I2C”);
delay(5000);
lcd.setCursor(0,0);
lcd.print(“BTN KANAN : “);
lcd.setCursor(0,1);
lcd.print(“BTN KIRI : “);
}
void loop()
{
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value
if (buttonState == LOW)
{
digitalWrite(buttonPin, LOW);
lcd.setCursor(12,0);
lcd.print(“ON “);
}else{
digitalWrite(buttonPin, HIGH);
lcd.setCursor(12,0);
lcd.print(“OFF “);
}
if (buttonState1 == LOW)
{
digitalWrite(buttonPin1, LOW);
lcd.setCursor(12,1);
lcd.print(“ON “);
}else{
digitalWrite(buttonPin1, HIGH);
lcd.setCursor(12,1);
lcd.print(“OFF “);
}
}