#include <SPI.h> //Library SPI
#include <Wire.h> //Library Wire
#include <Adafruit_GFX.h> //Library GFX
#include <Adafruit_SSD1306.h> //Library OLED SSD1306
#define SCREEN_WIDTH 128 //Panjang LCD OLED
#define SCREEN_HEIGHT 64 //Tinggi LCD OLED
#define OLED_RESET -1 //Pin reset terhubung dengan arduino
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //Alamat OLED
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
}
const unsigned char epd_bitmap_temperature [] PROGMEM = {
0xff, 0xf8, 0xf8, 0xf8, 0xf2, 0x78, 0xf7, 0x78, 0xf5, 0x78, 0xf5, 0x78, 0xf5, 0x78, 0xe8, 0xb8,
0xe8, 0xb8, 0xe8, 0xb8, 0xf7, 0x78, 0xfd, 0xf8, 0xff, 0xf8
};
const unsigned char epd_bitmap_barometer [] PROGMEM = {
0xff, 0xf8, 0xf0, 0x78, 0xe0, 0x38, 0xe7, 0x38, 0xc2, 0x18, 0xc2, 0x18, 0xe0, 0x38, 0xe0, 0x38,
0xf8, 0xf8, 0xf8, 0xf8, 0x80, 0x08, 0x80, 0x08, 0xff, 0xf8
};
const unsigned char epd_bitmap_height [] PROGMEM = {
0xff, 0xf8, 0xfd, 0xf8, 0xf8, 0xf8, 0xfd, 0xf8, 0xfd, 0xf8, 0xfd, 0xf8, 0xfd, 0xf8, 0xfd, 0xf8,
0xfd, 0xf8, 0xfd, 0xf8, 0xf8, 0xf8, 0xfd, 0xf8, 0xff, 0xf8
};
bool blinkState = false;
unsigned long previousMillis = 0;
const long interval = 500; // Blinking interval in milliseconds
void loop() {
unsigned long currentMillis = millis();
// Toggle blinkState every interval milliseconds
if (currentMillis - previousMillis >= interval) {
// Save the last time we blinked
previousMillis = currentMillis;
// Toggle the blink state
blinkState = !blinkState;
}
display.clearDisplay(); //clear before new display
display.setCursor(18,5);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Portable Weather");
display.drawBitmap(0, 16, epd_bitmap_temperature, 13, 13, 1);
display.setCursor(20,18);
display.setTextSize(1);
display.setTextColor(blinkState ? WHITE : BLACK); // Toggle visibility
display.print("20");
display.setTextColor(WHITE);
display.println(" *");
display.drawBitmap(0, 32, epd_bitmap_barometer, 13, 13, 1);
display.setCursor(20,34);
display.setTextSize(1);
display.setTextColor(blinkState ? WHITE : BLACK); // Toggle visibility
display.println("1260");
display.setTextColor(WHITE);
display.println(" hPa");
display.drawBitmap(0, 48, epd_bitmap_height, 13, 13, 1);
display.setCursor(20,50);
display.setTextSize(1);
display.setTextColor(blinkState ? WHITE : BLACK); // Toggle visibility
display.println("20");
display.setTextColor(WHITE);
display.println(" mDPL");
display.display(); //show data
}