Example Code for Arduino-Progress Bar
Last revision 2026/01/26
This article guides you through creating a dynamic progress bar on an OLED display using Arduino and the DFRobot library, featuring hardware and software setup, sample code, and expected results.
Hardware Preparation
- FireBeetle ESP32 IoT Microcontroller(SKU: DFR0478) ×1
- OLED128x64 Display - FireBeetle Covers(SKU: DFR0507) ×1
- USB Cable ×1
Software Preparation
- Download Arduino IDE: Click to Download Arduino IDE
- Download Arduino Library: Click to download DFRobot_OLED12864 and refer to the guide: How to Install a Library?
All of the following examples are belong to DFRobot_OLED12864 library files.
Sample Code
OLED12864 draws progress bar, updates percentage in real time.
#include "DFRobot_OLED12864.h" // alias for `#include "DFRobot_OLED12864Wire.h"`
// Initialize the OLED display using Wire library
DFRobot_OLED12864 display(0x3c);
int counter = 1;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println();
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
}
void drawProgressBarDemo()
{
int progress = (counter / 5) % 100;
// draw the progress bar
display.drawProgressBar(0, 32, 120, 10, progress);
// draw the percentage as String
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 15, String(progress) + "%");
}
void loop()
{
// clear the display
display.clear();
// draw the current demo method
drawProgressBarDemo();
// write the buffer to the display
display.display();
counter++;
delay(10);
}
Result
Display the progress bar on the screen.
Function Declaration
- Draw progress bar.
drawProgressBar(x, y, width, height, progress)
- Formatting fonts.
setTextAlignment(alignment)
- Draw string in specified location.
drawString(x, y, string)
Was this article helpful?
