Chris Styles
/
m3pi_BatteryCharger
Example code for charging a battery
Fork of m3pi_HelloWorld by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "m3pi.h" 00003 00004 m3pi m3pi; 00005 DigitalOut relay (p20); 00006 00007 void charge (float volts); 00008 void charge (float volts) 00009 { 00010 00011 volatile float current_volts = m3pi.battery(); 00012 00013 if (current_volts < volts) { // needs charging 00014 relay = 1; // switch relay on 00015 while (current_volts < volts) { 00016 current_volts = m3pi.battery(); 00017 m3pi.cls(); 00018 m3pi.locate(0,0); 00019 m3pi.printf("%.2f",current_volts); 00020 wait(10.0); 00021 } 00022 relay = 0; // switch relay off 00023 return; 00024 00025 } else { // no charege needed 00026 return; 00027 } 00028 00029 } 00030 00031 00032 int main() 00033 { 00034 00035 m3pi.locate(0,1); 00036 m3pi.printf("LO World"); 00037 00038 charge(4.8); // chrage to 4.8v 00039 00040 } 00041 00042
Generated on Thu Jul 14 2022 04:43:27 by 1.7.2