//==================================================================== // OLED DISPLAY //==================================================================== // LIBRARY INCLUDE //-------------------------------------------------------------------- // Include Libraries #include #include // Display Instance SSD1306Wire display(0x3c, 21, 22); //-------------------------------------------------------------------- // OLED Initialization //-------------------------------------------------------------------- void oled_init() { display.init(); display.flipScreenVertically(); display.setFont(ArialMT_Plain_10); } //-------------------------------------------------------------------- // OLED Display Text //-------------------------------------------------------------------- void drawTextFlowDemo(String Text) { display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawStringMaxWidth(0, 0, 128, Text); } //-------------------------------------------------------------------- // OLED LEFT TEXT Display //-------------------------------------------------------------------- void drawTextLeft() { display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawString(0, 10, "Left aligned (0,10)"); } //-------------------------------------------------------------------- // OLED CENTER TEXT Display //-------------------------------------------------------------------- void drawTextCenter(int X, int Y, int Size, String Text) { //display.setFont(ArialMT_Plain_10); if(Size == 1) { display.setFont(ArialMT_Plain_10); } else if(Size == 2) { display.setFont(ArialMT_Plain_16); } else if(Size == 3) { display.setFont(ArialMT_Plain_24); } else { display.setFont(ArialMT_Plain_10); } display.setTextAlignment(TEXT_ALIGN_CENTER); display.drawString(X, Y, Text); } //-------------------------------------------------------------------- // OLED RIGHT TEXT DISPLAY //-------------------------------------------------------------------- // OLED Display void drawTextRight() { display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_RIGHT); display.drawString(128, 33, "Right aligned (128,33)"); } //-------------------------------------------------------------------- // OLED DRAW RECTANGLE //-------------------------------------------------------------------- void drawRectDemo() { // Draw a pixel at given position for (int i = 0; i < 10; i++) { display.setPixel(i, i); display.setPixel(10 - i, i); } display.drawRect(12, 12, 20, 20); // Fill the rectangle display.fillRect(14, 14, 17, 17); // Draw a line horizontally display.drawHorizontalLine(0, 40, 20); // Draw a line horizontally display.drawVerticalLine(40, 0, 20); } //-------------------------------------------------------------------- // OLED DRAW CIRCLE //-------------------------------------------------------------------- void drawCircleDemo() { for (int i=1; i < 8; i++) { display.setColor(WHITE); display.drawCircle(32, 32, i*3); if (i % 2 == 0) { display.setColor(BLACK); } display.fillCircle(96, 32, 32 - i* 3); } } //-------------------------------------------------------------------- // OLED DRAW PROGRESS BAR //-------------------------------------------------------------------- void drawProgressBarDemo(int Value) { int progress = Value; // draw the progress bar display.drawProgressBar(0, 50, 120, 10, progress); // draw the percentage as String display.setTextAlignment(TEXT_ALIGN_CENTER); display.drawString(64, 35, String(progress) + "%"); } //-------------------------------------------------------------------- // OLED CLEAR DISPLAY //-------------------------------------------------------------------- void oled_clear() { display.clear(); } //-------------------------------------------------------------------- // OLED SHOW NEW DATA //-------------------------------------------------------------------- void oled_show() { display.display(); } //-------------------------------------------------------------------- // OLED DISPLAY KICKER WELCOME MESSAGE //-------------------------------------------------------------------- void kicker_logo() { // Starting The First Code oled_clear(); drawTextCenter(128/2, 5, 3, "TAKEONE"); drawTextCenter(128/2, 30, 1, " - T E C H N O L O G Y - "); drawTextCenter(128/2, 43, 2, "<< KICKER >>"); oled_show(); } //-------------------------------------------------------------------- // OLED DISPLAY BATTERY LEVEL //-------------------------------------------------------------------- void battery_level_display() { // Counting Time timetick = millis(); // Taking Action Based On Time Count if(timetick - prevtick >= 5000) { prevtick = timetick; String BV = String(BATTERY,2); String BC = String(CHARGE, 0); oled_clear(); drawTextFlowDemo("Battery Level : " + BV + " V Charge Level : " + BC + "%"); drawProgressBarDemo(BC.toInt()); oled_show(); } }