Simple Circular Progress Bar

Hi

After a fruitless search of a simple circular progress bar I made a very simple one myself.
Here's the code. It's made for the M5Stack Core2 but should be easy to use on any MCU.
Delay can be changed for a "blink without delay" style instead, or in many occasions it might be the case that the processing time of the other code in the loop is enough delay.
Please note the resolution affects the speed of the progress bar as well as the delay.

/********************************************
 * Simple Circular Progress Bar             *
 * for M5Stack Core2                        *
 * Can easily be adapted for other MCU's    *
 * by Thomas Nilsson 2022                   *
 * ******************************************/

#include <Arduino.h>
#include <M5Core2.h>

#define col1        BLUE      // Set first color
#define col2        BLACK     // Set second color
#define resolution  50        // Set resolution of circular progress bar
#define radius      50        // Set radius of the circular progress bar
#define width       7         // Set width of the circular progress bar

int xp = 160, yp = 150;       // Set x and y position of circular progress bar.
int xd, yd, fillcol;  
float rad = 0;

void setup()
{
    M5.begin();
}

void loop()
{
    rad += 6.28/resolution;
    if (rad > 6.28){
      rad = 0;
      fillcol = fillcol ^ col1 ? col1 : col2;
    }
    xd = (int)(radius * cos(rad));
    yd = (int)(radius * sin(rad));
    M5.Lcd.fillCircle(xp+xd, yp+yd, width, fillcol);
    delay(10);
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.