I made a function that creates a bar graph, for anyone interested. To use it, simply add this to your glcd.cpp file:
void glcd::BarGraph(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t fullval, uint8_t currentval){
float range = (float)width / (float)fullval;
int currentwidth = currentval * range;
GLCD.DrawRect(x, y, width, height);
for (int i = 1; i < height; i++) {
GLCD.DrawHLine(x, y+i, currentwidth);}
GLCD.FillRect(x+currentwidth+1, y+1, width-currentwidth-2, height-2, WHITE);
}
And this to your glcd.h file:
void BarGraph(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t max, uint8_t current);
Here is an example, that fills the graph as a clock counts up:
#include <glcd.h>
#include "fonts/fixednums15x31.h"
long sec = 0;
int min = 0;
long starttime;
void setup() {
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
}
void loop() {
gText ClockArea;
ClockArea.DefineArea(20, 0, 6, 1, fixednums15x31);
ClockArea.CursorToXY(2,0);
sec = (millis() - starttime) / 1000;
if (sec > 59) {
min++;
sec = 0;
starttime = millis();
}
if (min < 10) {
ClockArea.print(0);}
ClockArea.print(min);
ClockArea.print(":");
if (sec < 10) {
ClockArea.print(0);}
ClockArea.print(sec);
GLCD.BarGraph(10, 40, 108, 8, 59, sec);
}
Syntax:
GLCD.BarGraph(toprightx, toprighty, width, height, fullvalue, currentvalue);