![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
Diff: UI/LCD/Bargraph.cpp
- Revision:
- 0:a6a169de725f
diff -r 000000000000 -r a6a169de725f UI/LCD/Bargraph.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/LCD/Bargraph.cpp Mon May 27 13:26:03 2013 +0000 @@ -0,0 +1,67 @@ +#include "Bargraph.h" + +#define CHAR_WIDTH 6 +#define WIDTH 8 +#define HEIGHT 9 + +SerialGraphicLCD *Bargraph::lcd = 0; + +Bargraph::Bargraph(int x, int y, int size, char name): + _x(x), _y(y), _x2(x+WIDTH), _y2(y+size-1), _s(size), _n(name), _last(0) +{ +} + +Bargraph::Bargraph(int x, int y, int size, int width, char name): + _x(x), _y(y), _x2(x+width-1), _y2(y+size-1), _s(size), _w(width), _n(name), _last(0) +{ +} + +void Bargraph::init() +{ + if (lcd) { + if (_n != ' ') { + lcd->posXY(_x + (_w/2 - CHAR_WIDTH/2), _y2+2); // horizontal center + //wait_ms(5); + lcd->printf("%c", _n); + //wait_ms(5); + } + lcd->rect(_x, _y, _x2, _y2, true); + //wait_ms(5); // doesn't seem to help + int value = _last; + _last = 0; + update(value); + } +} + +void Bargraph::calibrate(float min, float max) +{ + _min = min; + _max = max; +} + +void Bargraph::update(float value) +{ + int ivalue; + + ivalue = (int) ((value - _min) * (_s-1)/(_max - _min)); + + update(ivalue); + + return; +} + +void Bargraph::update(int value) +{ + if (lcd) { + if (value >= 0 && value < _s) { + int newY = _y2-value; + + for (int y=_y+1; y < _y2; y++) { + lcd->line(_x+1, y, _x2-1, y, (y > newY)); + wait_ms(8); + } + } + _last = value; + } +} +