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.
Dependencies: mbed
Revision 17:793f819e1df6, committed 2022-01-31
- Comitter:
- legstar85
- Date:
- Mon Jan 31 20:41:38 2022 +0000
- Parent:
- 16:c63a5d084db0
- Commit message:
- Tidy of code, comments, functions updated
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jan 27 08:00:52 2022 +0000
+++ b/main.cpp Mon Jan 31 20:41:38 2022 +0000
@@ -96,8 +96,15 @@
void Run(); //
void StartTemp(); //
void delete_file(char filename[]); //
- //
- //
+void HighTemp(); //
+void SuperHighTemp(); //
+void UltraHighTemp(); //
+void LowTemp(); //
+void SuperLowTemp(); //
+void UltraLowTemp(); //
+void PeripheralsOffHigh(); //
+void PeripheralsOffLow(); //
+ //
int main() //
{ //
init_K64F(); // Initialise the board
@@ -191,7 +198,7 @@
lcd.printString(" Smart Cold",0,1); // Just a welcome message before auto moving to main menu
lcd.printString(" Storage",0,2); //
lcd.printString(" Monitoring",0,3); //
- lcd.printString("V17 - Jan 2022",0,4); //
+ lcd.printString("V18 - Jan 2022",0,4); //
lcd.printString("--------------",0,5); //
lcd.refresh(); // Need to refresh display after setting pixels or writing strings
wait(5.0); // Leave welcome screen on for designated amount of time
@@ -330,7 +337,7 @@
} //
//
float T = tmp102.get_temperature(); // read temperature and print to lcd
- pc.printf("T = %f K\n",T); // Print to serial - allows testing without device attached
+ pc.printf("T = %f C\n",T); // Print to serial - allows testing without device attached
int length = sprintf(buffer," T = %.2f C",T); // print formatted data to buffer - it is important the format specifier ensures the length will fit in the buffer
if (length <= 14) // if string will fit on display (assuming printing at x=0)
lcd.printString("-- Constant --",0,0); //
@@ -340,49 +347,37 @@
lcd.refresh(); // need to refresh display after setting pixels or writing strings
wait(0.5); //
//
- if (T >= g_StartTemp + 2) { // High temp alarm condition - in real world would be lot lower!!
- LED01 = !LED01; // Flash LED01 if temperature is over specified - Simulated starting of cold blowers
- LED02 = !LED02; // Flash LED02 if temperature is over specified - Simulated starting of cold blowers
- LED03 = !LED03; // Flash LED03 if temperature is over specified - Simulated starting of cold blowers
- printf("WARNING - High Temp!! \n"); //
- Buzzer.period(1.0/554.0); // Warning Buzzer to extremely high
- Buzzer = 0.5; //
- wait(0.5); //
- Buzzer = 0; //
+ if (T >= g_StartTemp + 2 and T < g_StartTemp + 4) { // High temp alarm condition - in real world would be lot lower!!
+ HighTemp(); //
} //
else { //
- LED01 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
- LED02 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
- LED03 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
- Buzzer = 0; // Buzzer off if temperature is below specified - Simulated stopping of cold blowers
+ PeripheralsOffHigh(); //
+ } //
+ if (T >= g_StartTemp + 4 and T < g_StartTemp + 6) { // High temp alarm condition - in real world would be lot lower!!
+ SuperHighTemp(); //
} //
- //
- if (T <= g_StartTemp - 2) { // High temp alarm condition - in real world would be lot lower!!
- LED04 = !LED04; // Flash LED01 if temperature is over specified - Simulated starting of heaters
- LED05 = !LED05; // Flash LED02 if temperature is over specified - Simulated starting of heaters
- LED06 = !LED06; // Flash LED03 if temperature is over specified - Simulated starting of heaters
- printf("WARNING - Low Temp!! \n"); //
- Buzzer.period(1.0/554.0); // Warning Buzzer to extremely low
- wait(0.5); //
- Buzzer = 0; //
+ else { //
+ PeripheralsOffHigh(); //
+ } //
+ if (T >= g_StartTemp + 6) { //
+ UltraHighTemp(); //
+ } //
+ else { //
+ PeripheralsOffHigh(); //
+ } //
+ if (T <= g_StartTemp - 2 and T > g_StartTemp - 4) { // Low temp alarm condition - in real world would be lot lower!!
+ LowTemp(); //
} //
else { //
- LED04 = 1; // LED01 off if temperature is below specified - Simulated stopping of heaters
- LED05 = 1; // LED01 off if temperature is below specified - Simulated stopping of heaters
- LED06 = 1; // LED01 off if temperature is below specified - Simulated stopping of heaters
- Buzzer = 0; // Buzzer off if temperature is below specified - Simulated stopping of heaters
+ PeripheralsOffLow(); //
} //
if(bAButtonWasPressed) // Check if button was pressed
{ //
if(SelectedItem == 0) //
{ //
NewMenuState = MENUSTATE_Main; // Transition back to the main menu
- LED01 = 1; // Turn off LED upon transition back to main menu
- LED02 = 1; // Turn off LED upon transition back to main menu
- LED03 = 1; // Turn off LED upon transition back to main menu
- LED04 = 1; // Turn off LED upon transition back to main menu
- LED05 = 1; // Turn off LED upon transition back to main menu
- LED06 = 1; // Turn off LED upon transition back to main menu
+ PeripheralsOffHigh(); //
+ PeripheralsOffLow(); //
} //
} //
} //
@@ -437,7 +432,7 @@
} //
//
if (fp == NULL) { // if it can't open the file then print error message
- printf("Error! Unable to open file! Returning to main menu.\n"); //
+ printf("Error! Unable to open file! Returning to main menu.\n"); //
NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
} //
else //
@@ -576,7 +571,86 @@
{ //
Direction d = joystick.get_direction(); //
//
- g_StartTemp = fsm[g_state].output; // set ouput depending on current state
- wait(fsm[g_state].time); // wait in that state for desired time
- g_state = fsm[g_state].nextState[d]; // read input and update curent state
+ g_StartTemp = fsm[g_state].output; // Set ouput depending on current state
+ wait(fsm[g_state].time); // Wait in that state for desired time
+ g_state = fsm[g_state].nextState[d]; // Read input and update curent state
+} //
+ //
+void HighTemp() //
+{ //
+ LED01 = !LED01; // Flash LED01 if temperature is over specified - Simulated starting of cold blowers
+ printf("WARNING - High Temp!! \n"); //
+ Buzzer.period(1.0/554.0); // Warning Buzzer to extremely high
+ Buzzer = 0.5; //
+ wait(0.5); //
+ Buzzer = 0; //
+} //
+ //
+void SuperHighTemp() //
+{ //
+ LED01 = !LED01; // Flash LED01 if temperature is over specified - Simulated starting of cold blowers
+ LED02 = !LED02; // Flash LED02 if temperature is over specified - Simulated starting of cold blowers
+ printf("WARNING - Super High Temp!! \n"); //
+ Buzzer.period(1.0/554.0); // Warning Buzzer to extremely high
+ Buzzer = 0.5; //
+ wait(0.5); //
+ Buzzer = 0; //
+} //
+ //
+void UltraHighTemp() //
+{ //
+ LED01 = !LED01; // Flash LED01 if temperature is over specified - Simulated starting of cold blowers
+ LED02 = !LED02; // Flash LED02 if temperature is over specified - Simulated starting of cold blowers
+ LED03 = !LED03; // Flash LED02 if temperature is over specified - Simulated starting of cold blowers
+ printf("WARNING - Ultra High Temp!! \n"); //
+ Buzzer.period(1.0/554.0); // Warning Buzzer to extremely high
+ Buzzer = 0.5; //
+ wait(0.5); //
+ Buzzer = 0; //
} //
+ //
+void LowTemp() //
+{ //
+ LED04 = !LED04; // Flash LED04 if temperature is over specified - Simulated starting of heaters
+ printf("WARNING - Low Temp!! \n"); //
+ Buzzer.period(1.0/554.0); // Warning Buzzer to extremely low
+ wait(0.5); //
+ Buzzer = 0; //
+} //
+ // //
+void SuperLowTemp() //
+{ //
+ LED04 = !LED04; // Flash LED04 if temperature is over specified - Simulated starting of heaters
+ LED05 = !LED05; // Flash LED05 if temperature is over specified - Simulated starting of heaters
+ printf("WARNING - Super Low Temp!! \n"); //
+ Buzzer.period(1.0/554.0); // Warning Buzzer to extremely low
+ wait(0.5); //
+ Buzzer = 0; //
+} //
+ //
+void UltraLowTemp() //
+{ //
+ LED04 = !LED04; // Flash LED04 if temperature is over specified - Simulated starting of heaters
+ LED05 = !LED05; // Flash LED05 if temperature is over specified - Simulated starting of heaters
+ LED06 = !LED06; // Flash LED06 if temperature is over specified - Simulated starting of heaters
+ printf("WARNING - Ultra Low Temp!! \n"); //
+ Buzzer.period(1.0/554.0); // Warning Buzzer to extremely low
+ wait(0.5); //
+ Buzzer = 0; //
+} //
+ //
+void PeripheralsOffHigh() //
+{ //
+ LED01 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
+ LED02 = 1; // LED02 off if temperature is below specified - Simulated stopping of cold blowers
+ LED03 = 1; // LED03 off if temperature is below specified - Simulated stopping of cold blowers
+ Buzzer = 0; // Buzzer off if temperature is below specified - Simulated stopping of cold blowers
+} //
+ //
+void PeripheralsOffLow() //
+{ //
+ LED04 = 1; // LED04 off if temperature is below specified - Simulated stopping of heaters
+ LED05 = 1; // LED05 off if temperature is below specified - Simulated stopping of heaters
+ LED06 = 1; // LED06 off if temperature is below specified - Simulated stopping of heaters
+ Buzzer = 0; // Buzzer off if temperature is below specified - Simulated stopping of heaters
+} //
\ No newline at end of file