#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_I2C
//#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
static const unsigned char image_arrow_curved_left_up_down_bits[] = {0x44,0x36,0x1f,0x06,0x04};
const char* menuItems[] = {"Info", "Settings", "Hello", "Logo"};
const int menuSize = sizeof(menuItems) / sizeof(menuItems[0]);
int currentMenuItem = 0;
const int potPin = 4; // Assuming potentiometer is connected to pin 4
TaskHandle_t Blink;
TaskHandle_t menu;
void setup(void) {
Serial.begin(115200);
u8g2.begin();
pinMode(potPin, INPUT);
xTaskCreatePinnedToCore(
Blink_func,
"Blink",
10000,
NULL, /* Task input parameter */
0, /* Priority of the task */
&Blink, /* Task handle. */
0);
xTaskCreatePinnedToCore(
menu_func,
"menu",
10000,
NULL, /* Task input parameter */
0, /* Priority of the task */
&Blink, /* Task handle. */
0);
Serial.println("Setup completed");
}
void Blink_func(void * TaskParameters_t){
for(;;){
static const unsigned char image_download_bits[] = {0x00,0x00,0x80,0x01,0x40,0x02,0x40,0x02,0x20,0x04,0x90,0x09,0x90,0x09,0x88,0x11,0x88,0x11,0x84,0x21,0x02,0x40,0x82,0x41,0x81,0x81,0x01,0x80,0xfe,0x7f,0x00,0x00};
u8g2.setFontMode(1);
u8g2.setBitmapMode(1);
u8g2.drawXBM(110, 1, 16, 16, image_download_bits);
u8g2.sendBuffer();
}
}
void menu_func(void * TaskParameters_t){
for(;;){
//u8g2.clearBuffer();
u8g2.setFontMode(1);
u8g2.setBitmapMode(1);
u8g2.drawFrame(0, 0, 128, 16);
u8g2.drawFrame(0, 16, 128, 48);
u8g2.drawFrame(4, 32, 120, 16);
u8g2.drawLine(5, 48, 124, 48);
u8g2.drawLine(124, 33, 124, 47);
u8g2.drawXBMP(3, 55, 7, 5, image_arrow_curved_left_up_down_bits);
u8g2.setFont(u8g2_font_5x8_tr);
u8g2.drawStr(4, 11, "Open & Hack");
u8g2.drawStr(8, 43, menuItems[currentMenuItem]);
u8g2.sendBuffer();
}
}
void loop(void) {
int potValue = analogRead(potPin);
currentMenuItem = map(potValue, 0, 4095, 0, menuSize - 1);
delay(100); // Small delay to avoid too frequent updates
}