#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
// Initialize for SH1107 128x128 I2C
// Format: U8G2_SH1107_128X128_F_HW_I2C u8g2(Rotation, [reset], [clock], [data])
U8G2_SH1107_128X128_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
const int BUTTON_PIN = 13;
bool botMode = false;
unsigned long lastTick = 0;
// Variables
int h = 4, m = 41, s = 0;
float btcPrice = 64250.0;
void setup() {
u8g2.begin();
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
// Update Time and Simulation
if (millis() - lastTick >= 1000) {
lastTick = millis();
s++;
if(s > 59) { s = 0; m++; }
if(m > 59) { m = 0; h++; }
if(h > 23) { h = 0; }
btcPrice += (random(-100, 101) / 10.0);
}
// Toggle Mode
if (digitalRead(BUTTON_PIN) == LOW) {
botMode = !botMode;
delay(300);
}
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
if (!botMode) {
// --- WATCH FACE ---
u8g2.drawStr(40, 20, "WATCH");
u8g2.setFont(u8g2_font_logisoso24_tn);
char timeStr[9];
sprintf(timeStr, "%02d:%02d:%02d", h, m, s);
u8g2.drawStr(10, 75, timeStr);
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(25, 110, "Press to Trade");
}
else {
// --- BOT FACE ---
u8g2.drawStr(0, 20, "BTC/EUR BOT");
u8g2.setFont(u8g2_font_logisoso16_tf);
u8g2.setCursor(0, 60);
u8g2.print(btcPrice, 1);
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0, 90);
u8g2.print("Investment: 100 EUR");
u8g2.setCursor(0, 110);
u8g2.print("PnL: ");
u8g2.print(btcPrice - 64250.0);
}
u8g2.sendBuffer();
}Loading
grove-oled-sh1107
grove-oled-sh1107