Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 29:7475bcdce4e6
- Parent:
- 28:216a26d99858
- Child:
- 30:ad77e3ee288b
--- a/main.cpp Wed Dec 05 13:49:05 2018 +0000 +++ b/main.cpp Wed Dec 05 14:29:51 2018 +0000 @@ -27,7 +27,7 @@ //Charging data #define POLL_BATT_CYCLE 5 //Poll the battery every 3 loops #define LOW_BATTERY_VOLTAGE 4.6 //measured voltage where charging is required -#define VOLTAGE_AT_PIT 4.9 //min initial voltage across charger when car enter the pit +#define VOLTAGE_AT_PIT 4.7 //min initial voltage across charger when car enter the pit #define CHARGE_TIME 20 //in seconds. 1200 seconds = 20 minutes #define CHARGE_AMPS 1.0 //constant amps being delivered through charger #define CHARGE_DELTA_T 1.0 //seconds polls voltage and integrates in 1 second steps @@ -80,7 +80,7 @@ float charge(int charge_time); //Prototypes: Displaying -void show_voltage(); +void show_voltage(char* message); void show_car_data(performance_data data); @@ -100,12 +100,12 @@ int sensor_values[NUM_REFL_SENSORS]; //array for reflectance sensor values bool battery_low_flag = false; //goes true when battery needs charging bool pit_crossroad_flag = false; //goes true when car is at the pit crossrd - bool button_pressed_flag = false; //goes true when the button has been prs + // bool button_pressed_flag = false; //goes true when the button has been prs DigitalOut pit_light(LED1); //Blue LED on mbed, lights up when in pit DigitalOut low_batt_light(p20); //Red LED on expansion board - int mod_batt = 0; //modded counter to control how often sensors are polled +// int mod_batt = 0; //modded counter to control how often sensors are polled //define the button: user push button on p21 DigitalIn button(p21); @@ -146,9 +146,9 @@ pit_crossroad_flag = car_at_pit_crossroad(sensor_values); //anden frekvens? //Detect button press... Do we need to debounce the button? - if (button == 0) { - button_pressed_flag = true; - } + // if (button == 0) { + // button_pressed_flag = true; + // } /* @@ -158,7 +158,7 @@ */ //if the button is pressed, show some stats on the display - if ( button_pressed_flag ) { + /* if ( button_pressed_flag ) { //call the function to print car data show_car_data(car_data); @@ -166,7 +166,7 @@ //reset the flag button_pressed_flag = false; } - + */ //if low_batt: decellerate car (slow down) and continue to pit if ( battery_low_flag ) { speed = (speed > PIT_SPEED) ? speed-DECELLERATION : PIT_SPEED; @@ -188,7 +188,12 @@ pit_navigate(ENTER_PIT); //Check whether the car has connected to the charger - wait(0.3); + //and show voltage at the same time + for (int i = 0; i < 6; i++) { + show_voltage("Waiting"); + wait(0.5); + } + if ( m3pi.battery() >= VOLTAGE_AT_PIT ) { //we have connected to the charging poles @@ -438,7 +443,7 @@ for (int i = 0; i < timesteps; i++) { - show_voltage(); + show_voltage("Charging"); // PERFORM SOME WEIRD CALCULATION HERE @@ -455,7 +460,11 @@ //Show the battery voltage in the display -void show_voltage() { +void show_voltage(char* message) { + m3pi.cls(); + m3pi.locate(0,0); + m3pi.printf("%s", message); + m3pi.locate(0,1); m3pi.printf("%07.2fV", m3pi.battery() ); }