File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
avr/libraries/LottieLemon/examples/Robot_Motor_Battery_Test Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ /* Motor Core with battery stats readout.
2+
3+ This code for the Arduino Robot's motor board
4+ is the stock firmware with added code printing
5+ the battery status.
6+
7+ */
8+
9+ #include < TwoWayIntegerEasyTransfer.h>
10+ #include < LottieLemon.h>
11+ #include < SoftwareSerial.h>
12+
13+ enum {
14+ SW_RX = SDA,
15+ SW_TX = SCL
16+ };
17+
18+ SoftwareSerial swSerial{ SW_RX, SW_TX };
19+
20+ LottieLemon::MotorBoard motorBoard;
21+
22+ void setup () {
23+ // start serial communication
24+ swSerial.begin (19200 );
25+ // initialize the libraries
26+ Serial1.begin (9600 );
27+ TwoWayIntegerEasyTransfer.begin (&Serial1);
28+ TwoWayIntegerEasyTransfer.attach ([]() { doSystemReset (); });
29+ doSystemReset ();
30+ }
31+
32+ void loop () {
33+ if (TwoWayIntegerEasyTransfer.hasReceivedData ()) {
34+ TwoWayIntegerEasyTransfer.processInput ();
35+ }
36+ motorBoard.run ();
37+
38+ measureBattery ();
39+ }
40+
41+ void doSystemReset () {
42+ motorBoard.reset ();
43+ }
44+
45+ void measureBattery () {
46+ static String bar; // string for storing the information
47+ static unsigned long tStart = millis ();
48+ unsigned long tStop = millis ();
49+ if ((tStop - tStart) > 100 ) {
50+ bar = String (" " ); // empty the string
51+ // read the sensors and add them to the string
52+ bar = bar + " Vbat=" + motorBoard.getBatteryTerminalVolts () + ' V' +
53+ " \t Icharge=" + motorBoard.getBatteryChargeMilliamps () + " mA" +
54+ " \t Idischarge=" + motorBoard.getBatteryDischargeMilliamps () + " mA" ;
55+
56+ swSerial.println (bar);
57+ tStart = tStop;
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments