Chris Styles
/
m3pi_BatteryCharger
Example code for charging a battery
Fork of m3pi_HelloWorld by
main.cpp@8:c0d66bb36209, 2013-01-18 (annotated)
- Committer:
- chris
- Date:
- Fri Jan 18 16:44:41 2013 +0000
- Revision:
- 8:c0d66bb36209
- Parent:
- 7:d0689e8f23bf
first check in
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:93bba564574a | 1 | #include "mbed.h" |
chris | 0:93bba564574a | 2 | #include "m3pi.h" |
chris | 0:93bba564574a | 3 | |
chris | 7:d0689e8f23bf | 4 | m3pi m3pi; |
chris | 8:c0d66bb36209 | 5 | DigitalOut relay (p20); |
chris | 0:93bba564574a | 6 | |
chris | 8:c0d66bb36209 | 7 | void charge (float volts); |
chris | 8:c0d66bb36209 | 8 | void charge (float volts) |
chris | 8:c0d66bb36209 | 9 | { |
chris | 8:c0d66bb36209 | 10 | |
chris | 8:c0d66bb36209 | 11 | volatile float current_volts = m3pi.battery(); |
chris | 8:c0d66bb36209 | 12 | |
chris | 8:c0d66bb36209 | 13 | if (current_volts < volts) { // needs charging |
chris | 8:c0d66bb36209 | 14 | relay = 1; // switch relay on |
chris | 8:c0d66bb36209 | 15 | while (current_volts < volts) { |
chris | 8:c0d66bb36209 | 16 | current_volts = m3pi.battery(); |
chris | 8:c0d66bb36209 | 17 | m3pi.cls(); |
chris | 8:c0d66bb36209 | 18 | m3pi.locate(0,0); |
chris | 8:c0d66bb36209 | 19 | m3pi.printf("%.2f",current_volts); |
chris | 8:c0d66bb36209 | 20 | wait(10.0); |
chris | 8:c0d66bb36209 | 21 | } |
chris | 8:c0d66bb36209 | 22 | relay = 0; // switch relay off |
chris | 8:c0d66bb36209 | 23 | return; |
chris | 8:c0d66bb36209 | 24 | |
chris | 8:c0d66bb36209 | 25 | } else { // no charege needed |
chris | 8:c0d66bb36209 | 26 | return; |
chris | 8:c0d66bb36209 | 27 | } |
chris | 8:c0d66bb36209 | 28 | |
chris | 8:c0d66bb36209 | 29 | } |
chris | 8:c0d66bb36209 | 30 | |
chris | 8:c0d66bb36209 | 31 | |
chris | 8:c0d66bb36209 | 32 | int main() |
chris | 8:c0d66bb36209 | 33 | { |
chris | 0:93bba564574a | 34 | |
chris | 2:5a329194c74d | 35 | m3pi.locate(0,1); |
chris | 2:5a329194c74d | 36 | m3pi.printf("LO World"); |
chris | 8:c0d66bb36209 | 37 | |
chris | 8:c0d66bb36209 | 38 | charge(4.8); // chrage to 4.8v |
chris | 8:c0d66bb36209 | 39 | |
chris | 8:c0d66bb36209 | 40 | } |
chris | 0:93bba564574a | 41 | |
chris | 0:93bba564574a | 42 |