Shellminator V3.0.1
Simple Terminal
Loading...
Searching...
No Matches
Example 302 GUI Progress Advanced

Table of Contents

In this example, we’ll customize the progress bar we created earlier.

First, it’s always nice to display some custom text alongside the progress bar:

progress.setText("Working on something...");

If the process takes a while, it might be useful to show how long it has been running or even estimate how much time is left:

progress.setFormat("t");

The setFormat method takes a format string where each letter represents a specific function. Here are the available options:

  • s β†’ Seconds since the process started
  • m β†’ Minutes since the process started
  • t β†’ Time elapsed since the process started [mm:ss]
  • r β†’ Estimated remaining time [mm:ss]
  • SPACE β†’ Prints a blank space
  • | β†’ Prints a vertical separator

For example, if you want to display the elapsed time and the estimated remaining time, separated by a vertical line, use:

progress.setFormat("t | r");

You can also customize the progress bar color:

progress.setColor(Shellminator::GREEN);
@ GREEN
Green text color.

Live Demo

Whole Code

/*
* Created on Aug 10 2020
*
* Copyright (c) 2023 - Daniel Hajnal
* hajnal.daniel96@gmail.com
* This file is part of the Shellminator project.
* Modified 2023.05.13
*/
#include "Shellminator.hpp"
// Create a Shellminator object, and initialize it to use Serial
Shellminator shell( &Serial );
// Create a progress bar object and connect it to the shell.
uint32_t timerStart = 0;
uint32_t period = 100;
float percentage = 1.0;
float step = 1.0;
// System init section.
void setup(){
Serial.begin(115200);
// Clear the terminal
shell.clear();
Serial.println( "Program Start!" );
progress.setFormat( "t" );
progress.setText( "Working on something..." );
shell.begin( "arnold" );
shell.beginScreen( &progress );
}
// Infinite loop.
void loop(){
if( ( millis() - timerStart ) > period ){
timerStart = millis();
percentage += step;
if( percentage > 100.0 ){
step = -1.0;
percentage = 100.0;
}
if( percentage < 0.0 ){
step = 1.0;
percentage = 0.0;
}
progress.setPercentage( percentage );
}
shell.update();
}
Shellminator object.
This class can create a simple plotter object.
void setPercentage(float percentage_p)
Set current percentage.
void setText(const char *text_p)
Set progress text.
void setFormat(const char *format_p)
Format options.
void setColor(Shellminator::textColor_t color_p)
You can modify the color of the bar.