/* PIN OUT
* TOMBOL1 = GPIO16 = 16
* TOMBOL2 = GPIO17 = 17
* LED TOMBOL = GPIO5 = 5
* SDA = 21
* SCL = 22
*/
/* OLED DISPLAY */
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// inisialisasi OLED P x L
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
/*PUSH BUTTON*/
const int buttonPin1 = 16; // Pin tombol 1
const int buttonPin2 = 17; // Pin tombol 2
const int ledPin = 19;
void setup() {
Serial.begin(9600);
// PUSH BUTTON
pinMode(buttonPin1, INPUT); // Mengatur tombol 1 sebagai input dengan resistor pull-up
pinMode(buttonPin2, INPUT); // Mengatur tombol 2 sebagai input dengan resistor pull-up
// LED
pinMode(ledPin, OUTPUT);
// OLED DISPLAY
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); }
delay(500);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop() {
/*PUSH BUTTON*/
if (digitalRead(buttonPin1) == HIGH){
digitalWrite(ledPin, HIGH);
}
if (digitalRead(buttonPin2) == HIGH){
digitalWrite(ledPin, LOW);
}
}