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:
- 72:fad84371f431
- Parent:
- 71:4747e63eb48c
- Child:
- 73:0646bad028c5
--- a/main.cpp Wed Oct 12 12:03:11 2022 +0000 +++ b/main.cpp Tue Oct 25 07:55:44 2022 +0000 @@ -28,7 +28,6 @@ // Prototypes - void LED_Control(int ledNumber, int state); //Turn ledNumber to 1=on, 0 = off void LED_Blink(int ledNumber); // Make ledNumber blinik void LCD_CountDown(int num); //LCD Coundown function @@ -37,8 +36,8 @@ int PS_BatteryTest(void); // Test if to robot needs to goto pit void PS_PitStop(void); // void PS_CreateLog(void); // create a log file or resets it (WIP -void PS_AddStopToLog(void); // Add one to the log -// void PS_DisplayNumberofPS(void); // Display the final number on screen WIP +void PS_AddStopToLog(void); // Add one to the log +int PS_GetNumberofPS(void); // Display the final number on screen WIP void TE_CreateVoltageLog(void); // void TE_LogVoltage(int count); // test funktion that write the woltage each time the battry is checked @@ -61,9 +60,11 @@ /*Printing secret cat mission*/ LCD_InitialMessages(); + m3pi.sensor_auto_calibrate(); - /*Create pitlog used to log the number of pitstop */ + + /*Create logs used to log the number of pitstop */ PS_CreateLog(); // TE_CreateVoltageLog(); @@ -120,13 +121,15 @@ ccount++; } - // PS_DisplayNumberofPS(); } +/** + * LCD_InitialMessages -Prints iniatial secret mission + */ void LCD_InitialMessages(void){ - /*Prints iniatial secret mission*/ - + + m3pi.cls(); m3pi.locate(0,0); m3pi.printf("DESTROY"); @@ -151,22 +154,43 @@ m3pi.locate(0,0); m3pi.printf("** GO **"); - + wait (1.0); } - + +/** + * PS_DisplayPS - Display the number of pidstops from the log + */ + +void PS_DisplayPS(void){ + m3pi.cls(); + m3pi.locate(0,0); + m3pi.printf("PITSTOP:"); + m3pi.locate(0,1); + m3pi.printf("%d", GetNumberofPS() ); + +} +/** + * LCD_CountDown - display a countdown + * @num The number to count down from- + */ + void LCD_CountDown(int num){ - for (int i=0; i<num; i++) + for (int i=num; i>0; i--) { m3pi.cls(); m3pi.locate(0,0); m3pi.printf("** %d **", i); wait(1.0); } - } - +/** + * PS_BatteryTest - Test the batteri voltage if the robot is not headed for pi + * + *return: 0 if the battery is above the threshold- Return 1 if the robot needs to goto pit + */ + int PS_BatteryTest(void){ /* Test the batteri voltage if the robot is not headed for pit */ @@ -205,6 +229,10 @@ led4 = state; } } +/** + * LED_Blink - Make a LED blink + *@ledNumber - The number of the targeted LED + */ void LED_Blink(int ledNumber) { @@ -217,6 +245,10 @@ wait(a); } +/** + * PS_PitStop - Stops the robot and starts the signal + */ + void PS_PitStop(void) { m3pi.stop(); // stop all engine @@ -227,8 +259,12 @@ } } +/** + * PS_CreateLog - Create a pitstop log i none excist + * + * Return: The number of ppitstops as noted in the log + */ void PS_CreateLog(void){ -/* Create a pitlog file and test if it can open*/ FILE *fptr; if ((fptr = fopen(PITLOGPATH,"r")) == NULL){ @@ -266,8 +302,8 @@ fclose(fptr); } -/* -void PS_DisplayNumberofPS(void){ + +int PS_GetNumberofPS(void){ // Display the number i the pitstop recorded in the logfile FILE *fptr; int x; @@ -277,10 +313,11 @@ exit(1); } fscanf(fptr,"%d", &x); - printf("Final number of pits stops %d", x); + //printf("Final number of pits stops %d", x); fclose(fptr); + return x; } -*/ + void TE_CreateVoltageLog(void){ /* Create a voltagelog file and test if it can open*/