-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgressBar.ino
46 lines (34 loc) · 923 Bytes
/
ProgressBar.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <SoftTimers.h>
/**************************************************
*Show a progress bar on the serial port.
**************************************************/
SoftTimer barTimer; //millisecond timer
void setup() {
Serial.begin(115200);
//update timers
barTimer.setTimeOutTime(5000); // every 5 second.
//start counting
barTimer.reset();
}
const int MAX_BAR_LENGTH = 91; //bar has 30 character max
char barText[MAX_BAR_LENGTH];
char barCharacter = '*';
void loop() {
if (barTimer.getLoopCount() >= 3)
{
barTimer.reset();
}
//build a new progress bar
memset(barText, 0, MAX_BAR_LENGTH);
//get progress
double progress = barTimer.getProgress();
//convert progress to a bar length
int numBar = progress*(MAX_BAR_LENGTH-1);
//fill progress bar
for(int i=0; i<numBar; i++)
{
barText[i] = barCharacter;
}
//show progress bar
Serial.println(barText);
}