A class to display a value as a bar on either the on-board LEDs, or using LEDs connected to the pwm pins.
Diff: BarChart.h
- Revision:
- 0:db2aa0ada4f9
- Child:
- 1:6b38423b75db
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BarChart.h Tue Nov 09 19:30:45 2010 +0000 @@ -0,0 +1,75 @@ +#ifndef MBED_BAR_CHART_H +#define MBED_BAR_CHART_H + +#include "mbed.h" +/** Bar chart output class, based on an array of PwmOuts +* +* Example: + * @code + * // Display the voltage at pin 20 as a bar chart on the on-board LEDs + * #include "mbed.h" + * #include "BarChart.h" + * + * BarChart b; + * AnalogIn input(p20); + + * int main() { + * //Set the maximum and minimum LED brightness + * b.setOutputLimits(0.1,0.9); + * + * while(1) { + * b = input; + * //equivalent to b.show(in); + * + * wait(0.01); + * } + * } + * @endcode + */ +class BarChart { +public: + /** Create a Bar chart from the 4 LEDs mounted on the board */ + BarChart(); + /** Create a Bar chart from the (PWM) pins specified + * + * @param pxx the pins to use, lowest bar first + */ + BarChart(PinName p1, PinName p2, PinName p3, PinName p4, + PinName p5, PinName p6, PinName p7, PinName p8, + PinName p9, PinName p10, PinName p11, PinName p12, + PinName p13, PinName p14, PinName p15, PinName p16); + /** Set the range of input that will be provided to the BarChart + * + * @param min The lowest value that the barchart will display + * @param max The highest value that the barchart will display + */ + void setInputLimits(float min, float max); + /** Set the range of output that will be provided to the PWM pins + * + * @param min The lowest duty cycle of the PwmOuts + * @param max The highest duty cycle of the PwmOuts + */ + void setOutputLimits(float min, float max); + /** Output the value to the PwmOuts + * + * @param value The value to display + */ + void show(float value); + /** Shorthand for the show function */ + BarChart& operator = (float value) { + show(value); + return *this; + }; + ~BarChart(); +private: + PwmOut **_outputs; + int _numPins; + float _maxInput; + float _minInput; + float _maxOutput; + float _minOutput; + float _linearScale(float value); + void _init(); +}; + +#endif \ No newline at end of file