Chris Styles
/
m3pi_BatteryCharger
Example code for charging a battery
Fork of m3pi_HelloWorld by
Diff: main.cpp
- Revision:
- 8:c0d66bb36209
- Parent:
- 7:d0689e8f23bf
--- a/main.cpp Fri May 13 10:51:57 2011 +0000 +++ b/main.cpp Fri Jan 18 16:44:41 2013 +0000 @@ -2,22 +2,41 @@ #include "m3pi.h" m3pi m3pi; +DigitalOut relay (p20); -int main() { +void charge (float volts); +void charge (float volts) +{ + + volatile float current_volts = m3pi.battery(); + + if (current_volts < volts) { // needs charging + relay = 1; // switch relay on + while (current_volts < volts) { + current_volts = m3pi.battery(); + m3pi.cls(); + m3pi.locate(0,0); + m3pi.printf("%.2f",current_volts); + wait(10.0); + } + relay = 0; // switch relay off + return; + + } else { // no charege needed + return; + } + +} + + +int main() +{ m3pi.locate(0,1); m3pi.printf("LO World"); - - wait (2.0); + + charge(4.8); // chrage to 4.8v + +} - m3pi.forward(0.5); // Forward half speed - wait (0.5); // wait half a second - m3pi.left(0.5); // Turn left at half speed - wait (0.5); // wait half a second - m3pi.backward(0.5);// Backward at half speed - wait (0.5); // wait half a second - m3pi.right(0.5); // Turn right at half speed - wait (0.5); // wait half a second - m3pi.stop(); -} \ No newline at end of file