#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int pinLEDmerah = 2;
const int pinLEDkuning = 3;
const int pinLEDhijau = 4;
const int pinTombol1 = 10;
const int pinTombol2 = 11;
const int pinTombol3 = 12;
const int pinTombolSemua = 13;
const unsigned char mujaLogo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x78, 0x00, 0x1e, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x87, 0x9c, 0x00, 0x00,
0x00, 0x00, 0xfc, 0x00, 0x3f, 0x00, 0x00, 0x87, 0x43, 0x61, 0xfd, 0x31, 0xcf, 0x9e, 0x11, 0x80,
0x00, 0x00, 0xfe, 0x00, 0x7f, 0x00, 0x01, 0xcf, 0x63, 0x63, 0xfb, 0x71, 0xdf, 0xbf, 0x33, 0xc0,
0x00, 0x01, 0xff, 0x00, 0xff, 0x80, 0x03, 0xef, 0x67, 0x60, 0x63, 0x7b, 0xd8, 0x33, 0xb3, 0xc0,
0x00, 0x03, 0xff, 0x81, 0xff, 0xc0, 0x03, 0xff, 0x67, 0x60, 0x63, 0x7f, 0xd8, 0x31, 0xb3, 0xc0,
0x00, 0x07, 0xff, 0xc3, 0xff, 0xe0, 0x03, 0xff, 0x67, 0x60, 0x63, 0x7f, 0xdf, 0x31, 0xb3, 0x60,
0x00, 0x0f, 0xff, 0xe7, 0xff, 0xf0, 0x03, 0xb7, 0x67, 0x60, 0x63, 0x64, 0xdf, 0x31, 0xb3, 0x60,
0x00, 0x1f, 0xff, 0xe7, 0xff, 0xf8, 0x03, 0x87, 0x67, 0x60, 0x63, 0x60, 0xd8, 0x31, 0xb7, 0xe0,
0x00, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x87, 0x67, 0x60, 0x63, 0x60, 0xdc, 0x33, 0xb7, 0xe0,
0x00, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x86, 0x7f, 0x7e, 0x63, 0x60, 0xdf, 0xbf, 0x36, 0x70,
0x00, 0x7f, 0xcf, 0xff, 0xf3, 0xfe, 0x03, 0x06, 0x3e, 0x7c, 0x42, 0x40, 0x8f, 0x3e, 0x24, 0x30,
0x00, 0xff, 0x87, 0xff, 0xe3, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xff, 0x83, 0xff, 0xc1, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xff, 0x01, 0xff, 0x80, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x07, 0xfe, 0x00, 0xff, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x07, 0xfe, 0x00, 0x7e, 0x00, 0x7f, 0xe0, 0x08, 0x8e, 0x10, 0x88, 0x40, 0x43, 0x12, 0x10, 0x00,
0x0f, 0xfe, 0x00, 0x7e, 0x00, 0x7f, 0xf0, 0x0c, 0xd8, 0x10, 0x88, 0x40, 0x43, 0x12, 0x10, 0x00,
0x0f, 0xff, 0x00, 0x3c, 0x00, 0xff, 0xf0, 0x08, 0xcc, 0x20, 0xf8, 0x80, 0x44, 0x0c, 0x28, 0x00,
0x1f, 0xff, 0x80, 0x18, 0x01, 0xff, 0xf8, 0x08, 0xc6, 0x2c, 0xc8, 0xb0, 0x47, 0x8c, 0x68, 0x00,
0x1f, 0xff, 0xc0, 0x00, 0x03, 0xff, 0xf8, 0x0c, 0x81, 0x64, 0x89, 0x90, 0x44, 0x84, 0x4c, 0x00,
0x1f, 0xff, 0xe0, 0x00, 0x07, 0xff, 0xf8, 0x07, 0x8e, 0x44, 0x89, 0x10, 0x48, 0xc4, 0x44, 0x00,
0x3f, 0xff, 0xf0, 0x00, 0x0f, 0xfb, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x3f, 0xcf, 0xf0, 0x00, 0x1f, 0xf3, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x3f, 0xcf, 0xf8, 0x00, 0x1f, 0xf3, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xc7, 0xfc, 0x00, 0x3f, 0xe3, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xc3, 0xfe, 0x00, 0x7f, 0xc3, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xe1, 0xff, 0x00, 0xff, 0x87, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xe0, 0xff, 0x81, 0xff, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xf0, 0x7f, 0x81, 0xfe, 0x0f, 0xf0, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xf8, 0x7f, 0xc3, 0xfe, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x04, 0x00, 0x80, 0x00, 0x00, 0x00,
0x07, 0xfc, 0x3f, 0xc3, 0xfc, 0x3f, 0xe0, 0x79, 0xde, 0x52, 0xf4, 0xef, 0xf2, 0x3b, 0x9f, 0x80,
0x07, 0xfe, 0x1f, 0xe7, 0xf8, 0x7f, 0xe0, 0x6f, 0x52, 0x52, 0x15, 0x98, 0x96, 0x66, 0xd2, 0x80,
0x03, 0xff, 0x0f, 0xe7, 0xf0, 0xff, 0xc0, 0x47, 0xd2, 0x52, 0xf5, 0x10, 0x9c, 0x44, 0x52, 0x80,
0x01, 0xff, 0x0f, 0xe7, 0xf0, 0xff, 0x80, 0x6e, 0x12, 0x52, 0x95, 0x98, 0x9c, 0x66, 0xd2, 0x80,
0x00, 0xff, 0x8f, 0xe7, 0xf1, 0xff, 0x00, 0x79, 0xd2, 0x5e, 0xf4, 0xee, 0xcd, 0x3b, 0x92, 0x80,
0x00, 0xff, 0xcf, 0xe7, 0xf3, 0xfe, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xef, 0xe7, 0xf7, 0xfe, 0x00, 0x40, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xff, 0xe7, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1f, 0xff, 0xe7, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xff, 0xe7, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xff, 0xc3, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xff, 0xc3, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xff, 0x81, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xff, 0x81, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int stateLEDmerah = LOW;
int stateLEDkuning = LOW;
int stateLEDhijau = LOW;
int stateSemuaLED = LOW;
void setup() {
pinMode(pinLEDmerah, OUTPUT);
pinMode(pinLEDkuning, OUTPUT);
pinMode(pinLEDhijau, OUTPUT);
pinMode(pinTombol1, INPUT_PULLUP);
pinMode(pinTombol2, INPUT_PULLUP);
pinMode(pinTombol3, INPUT_PULLUP);
pinMode(pinTombolSemua, INPUT_PULLUP);
display.begin( SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay(); //set display oled menjadi kosong
display.drawBitmap(0, 0, mujaLogo, 128, 64, WHITE); //menampilkan gambar sesuai hasil convert image, myBitmap disesuaikan dengan nama variabel yang digunakan
display.setTextColor(1); //setting warna text yang akan ditampilkan
display.setTextSize(1); //setting ukuran text yang akan ditampilkan
display.display();
delay(5000);
}
void loop() {
if (digitalRead(pinTombol1) == LOW) {
delay(50);
if (digitalRead(pinTombol1) == LOW) {
stateLEDmerah = !stateLEDmerah;
digitalWrite(pinLEDmerah, stateLEDmerah);
while (digitalRead(pinTombol1) == LOW) {}
}
}
if (digitalRead(pinTombol2) == LOW) {
delay(50);
if (digitalRead(pinTombol2) == LOW) {
stateLEDkuning = !stateLEDkuning;
digitalWrite(pinLEDkuning, stateLEDkuning);
while (digitalRead(pinTombol2) == LOW) {}
}
}
if (digitalRead(pinTombol3) == LOW) {
delay(50);
if (digitalRead(pinTombol3) == LOW) {
stateLEDhijau = !stateLEDhijau;
digitalWrite(pinLEDhijau, stateLEDhijau);
while (digitalRead(pinTombol3) == LOW) {}
}
}
if (digitalRead(pinTombolSemua) == LOW) {
delay(50);
if (digitalRead(pinTombolSemua) == LOW) {
stateSemuaLED = !stateSemuaLED;
digitalWrite(pinLEDmerah, stateSemuaLED);
digitalWrite(pinLEDkuning, stateSemuaLED);
digitalWrite(pinLEDhijau, stateSemuaLED);
while (digitalRead(pinTombolSemua) == LOW) {}
}
}
tampilkanStatusOLED();
}
void tampilkanStatusOLED() {
display.clearDisplay();
if (stateLEDmerah == LOW && stateLEDkuning == LOW && stateLEDhijau == LOW) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("STAND BY");
} else {
if (stateLEDmerah == HIGH) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("LED 1");
display.setCursor(0, 30);
display.println("MENYALA");
} else if (stateLEDkuning == HIGH) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("LED 2");
display.setCursor(0, 30);
display.println("MENYALA");
} else if (stateLEDhijau == HIGH) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("LED 3");
display.setCursor(0, 30);
display.println("MENYALA");
} else if (stateLEDmerah == HIGH && stateLEDkuning == HIGH) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("LED 1-2");
display.setCursor(0, 30);
display.println("MENYALA");
} else if (stateLEDmerah == HIGH && stateLEDhijau == HIGH) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("LED 1-3");
display.setCursor(0, 30);
display.println("MENYALA");
} else if (stateLEDkuning == HIGH && stateLEDhijau == HIGH) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("LED 2-3");
display.setCursor(0, 30);
display.println("MENYALA");
} else if (stateLEDmerah == HIGH && stateLEDkuning == HIGH && stateLEDhijau == LOW) {
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("SEMUA LED");
display.setCursor(0, 30);
display.println("MENYALA");
}
}
display.display();
}