// Library for OLED DIsplay
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Contoh Code Button dan LED
int ledPin_1 = 15; // Pin LED
int ledPin_2 = 4;
int pushButton_1 = 14; // Pin Button
int pushButton_2 = 12; // Pin Button
int state_btn_1 = 0; // Status btn ( Boolean )
int state_btn_2 = 0; // Status btn ( Boolean )
void setup() {
//Serial.begin(115200);
pinMode(ledPin_1, OUTPUT);
pinMode(pushButton_1, INPUT);
pinMode(ledPin_2, OUTPUT);
pinMode(pushButton_2, INPUT);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // set position to display (x,y)
oled.println("If Condition:"); // set text
oled.display(); // display on OLED
}
void loop() {
oled.setTextSize(1.5);
oled.setTextColor(WHITE);
oled.setCursor(0, 12);
state_btn_1 = digitalRead(pushButton_1);
state_btn_2 = digitalRead(pushButton_2);
if (state_btn_1 == HIGH && state_btn_2 == LOW){
digitalWrite(ledPin_1, HIGH);
//Serial.println(" LED 1 MENYALA ");
oled.println("LED 1 MENYALA");
}
if ( state_btn_2 == HIGH && state_btn_1 == LOW){
digitalWrite(ledPin_2, HIGH);
//Serial.println(" LED 2 MENYALA ");
oled.println(" LED 2 MENYALA ");
} else {
digitalWrite(ledPin_1, LOW);
digitalWrite(ledPin_2, LOW);
oled.println(" SEMUA LED MATI ");
}
oled.display();
delay(1000);
oled.clearDisplay();
}