#include <U8g2lib.h>
#define PIN_DCC_IN 4
uint8_t Speed = 0;
uint8_t volume = 180;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 26, /* data=*/ 25);
void speed_task(void *ptr)
{
pinMode(PIN_DCC_IN, INPUT);
while (1)
{
Speed = map(analogRead(PIN_DCC_IN), 0, 4096, 0, 256);
vTaskDelay(100);
}
}
void setup() {
// put your setup code here, to run once:
u8g2.begin();
u8g2.enableUTF8Print();
xTaskCreatePinnedToCore(speed_task, "Give Speed", 1024 * 2, NULL, 11, NULL, 1);
}
void loop() {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_timB10_tf); // choose a suitable font
u8g2.drawStr(10, 14, "Spd ");
u8g2.setCursor(45, 14);
u8g2.print(Speed);
u8g2.drawStr(70, 14, "Vol ");
u8g2.setCursor(105, 14);
u8g2.print(volume);
u8g2.drawHLine(6, 16, 166);
u8g2.setFont(u8g2_font_helvR08_tf);
u8g2.setDrawColor(0);
u8g2.drawStr(6, 30, "CH01");
u8g2.setDrawColor(1);
u8g2.drawStr(70, 30, "CH02");
u8g2.drawStr(6, 45, "CH03");
u8g2.drawStr(70, 45, "CH04");
u8g2.drawStr(6, 60, "CH05");
u8g2.drawStr(70, 60, "CH06");
//----------Channel Grains------------
u8g2.setCursor(44, 30);
u8g2.print(u8x8_u8toa(random(0, 255), 3));
u8g2.setCursor(108, 30);
u8g2.print(u8x8_u8toa(0, 3));
u8g2.setCursor(44, 45);
u8g2.print(random(0, 255));
u8g2.setCursor(108, 45);
u8g2.print(random(0, 255));
u8g2.setCursor(44, 60);
u8g2.print(random(0, 255));
u8g2.setCursor(108, 60);
u8g2.print(random(0, 255));
u8g2.sendBuffer(); // transfer internal memory to the display
delay(1000);
}