Final tidy of code following installation of new sensor, more comments added prior to submission

Dependencies:   mbed

Committer:
legstar85
Date:
Fri Jan 21 22:33:32 2022 +0000
Revision:
14:3e9991fe64e5
Parent:
13:5ad65a688f3f
Child:
15:0cd78b44ea83
Addition of new menu option, start of coding for writing Temp data to SD card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
legstar85 4:0090145b3286 1 /*
legstar85 13:5ad65a688f3f 2 * Prints a string of characters to the screen buffer, string is cut off after the 83rd pixel.
legstar85 13:5ad65a688f3f 3 * @param x - the column number (0 to 83)
legstar85 13:5ad65a688f3f 4 * @param y - the row number (0-5) - the display is split into 6 banks - each bank can be considered a row
legstar85 13:5ad65a688f3f 5 *
legstar85 2:e0091b5311f1 6 * @ File main.cpp
legstar85 4:0090145b3286 7 * @ Author - David Leaming - 25574043
legstar85 9:d71b92c916f8 8 * @ Date - January 2022
legstar85 13:5ad65a688f3f 9 *
legstar85 2:e0091b5311f1 10 * Acknowledgements
legstar85 14:3e9991fe64e5 11 * Craig A. Evans, University of Leeds, TMP102 Library, Feb 2016
legstar85 14:3e9991fe64e5 12 * Dr Edmond Nurellari, University of Lincoln, Joystick, N5110 Libraries & SD Card Libraries
legstar85 13:5ad65a688f3f 13 * Paul Staron, Piezo Buzzer utility, April 2019
eencae 0:21a200b880d7 14 */
eencae 0:21a200b880d7 15
legstar85 2:e0091b5311f1 16 #include "mbed.h" // include the library header, ensure the library has been imported into the project
eencae 1:dd5fb735acf1 17 #include "TMP102.h"
legstar85 2:e0091b5311f1 18 #include "N5110.h"
legstar85 2:e0091b5311f1 19 #include "Joystick.h"
legstar85 2:e0091b5311f1 20 #include "Bitmap.h"
legstar85 14:3e9991fe64e5 21 #include "SDFileSystem.h"
eencae 0:21a200b880d7 22
legstar85 2:e0091b5311f1 23 TMP102 tmp102(I2C_SDA,I2C_SCL); // Create TMP102 object
legstar85 2:e0091b5311f1 24
legstar85 2:e0091b5311f1 25 // VCC,SCE,RST,D/C,MOSI,SCLK,LED
legstar85 2:e0091b5311f1 26 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // Create Screen Object - K64F - pwr from 3V3, GND Pin also needs connecting
legstar85 2:e0091b5311f1 27
legstar85 3:80c1eba78f9b 28 // y x button
legstar85 3:80c1eba78f9b 29 Joystick joystick(PTB10,PTB11,PTC16); // Define Joystick Object
eencae 0:21a200b880d7 30
legstar85 14:3e9991fe64e5 31 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS - Connections to SD card holder on K64F (SPI interface)
legstar85 14:3e9991fe64e5 32
legstar85 2:e0091b5311f1 33 Serial pc(USBTX,USBRX); // UART connection for PC
legstar85 2:e0091b5311f1 34
legstar85 11:a6eec09b546e 35 struct State { // Struct for state
legstar85 11:a6eec09b546e 36 int output; // output value
legstar85 11:a6eec09b546e 37 float time; // time in state
legstar85 11:a6eec09b546e 38 int nextState[9]; // array of next states
legstar85 11:a6eec09b546e 39 };
legstar85 11:a6eec09b546e 40
legstar85 11:a6eec09b546e 41 State fsm[11] = {
legstar85 12:5046b7515d5c 42 {15,0.5,{0,1,0,0,0,10,0,0,0}}, // State 0 - 15 Degrees
legstar85 12:5046b7515d5c 43 {16,0.5,{1,2,1,1,1,0,1,1,1}}, // State 1 - 16 Degrees
legstar85 12:5046b7515d5c 44 {17,0.5,{2,3,2,2,2,1,2,2,2}}, // State 2 - 17 Degrees
legstar85 12:5046b7515d5c 45 {18,0.5,{3,4,3,3,3,2,3,3,3}}, // State 3 - 18 Degrees
legstar85 12:5046b7515d5c 46 {19,0.5,{4,5,4,4,4,3,4,4,4}}, // State 4 - 19 Degrees
legstar85 12:5046b7515d5c 47 {20,0.5,{5,6,5,5,5,4,5,5,5}}, // State 5 - 20 Degrees
legstar85 12:5046b7515d5c 48 {21,0.5,{6,7,6,6,6,5,6,6,6}}, // State 6 - 21 Degrees
legstar85 12:5046b7515d5c 49 {22,0.5,{7,8,7,7,7,6,7,7,7}}, // State 7 - 22 Degrees
legstar85 12:5046b7515d5c 50 {23,0.5,{8,9,8,8,8,7,8,8,8}}, // State 8 - 23 Degrees
legstar85 12:5046b7515d5c 51 {24,0.5,{9,10,9,9,9,8,9,9,9}}, // State 9 - 24 Degrees
legstar85 13:5ad65a688f3f 52 {25,0.5,{10,1,10,10,10,9,10,10,10}} // State 10 - 25 Degrees
legstar85 11:a6eec09b546e 53 };
legstar85 11:a6eec09b546e 54
legstar85 5:eebd36a47049 55 Ticker ticker_menu; // Create Menu ticker object
legstar85 5:eebd36a47049 56
legstar85 2:e0091b5311f1 57 DigitalOut r_led(LED_RED); // K64F on-board LEDs
legstar85 2:e0091b5311f1 58 DigitalOut g_led(LED_GREEN); // K64F on-board LEDs
legstar85 2:e0091b5311f1 59 DigitalOut b_led(LED_BLUE); // K64F on-board LEDs
eencae 0:21a200b880d7 60
legstar85 8:07323fcab6d1 61 PwmOut LED01 (PTA1); // PCB Surface Mounted LED's - LED1
legstar85 8:07323fcab6d1 62 PwmOut LED02 (PTA2); // PCB Surface Mounted LED's - LED2
legstar85 8:07323fcab6d1 63 PwmOut LED03 (PTC2); // PCB Surface Mounted LED's - LED3
legstar85 8:07323fcab6d1 64 PwmOut LED04 (PTC3); // PCB Surface Mounted LED's - LED4
legstar85 8:07323fcab6d1 65 PwmOut LED05 (PTC4); // PCB Surface Mounted LED's - LED5
legstar85 8:07323fcab6d1 66 PwmOut LED06 (PTD3); // PCB Surface Mounted LED's - LED6
legstar85 8:07323fcab6d1 67
legstar85 8:07323fcab6d1 68 PwmOut Buzzer (PTC10); // PCB Surface Mounted Piezo Buzzer
legstar85 3:80c1eba78f9b 69
legstar85 2:e0091b5311f1 70 InterruptIn sw2(SW2); // K64F on-board switches
legstar85 2:e0091b5311f1 71 InterruptIn sw3(SW3); // K64F on-board switches
legstar85 3:80c1eba78f9b 72 InterruptIn ButtonA (PTB9); // PCB Button - A
legstar85 3:80c1eba78f9b 73 InterruptIn ButtonB (PTD0); // PCB Button - B
legstar85 7:d77e95505e43 74 InterruptIn ButtonBack (PTB10); // PCB Button - Back
legstar85 3:80c1eba78f9b 75
legstar85 12:5046b7515d5c 76 volatile int g_ButtonA_flag = 0; // Flag - must be volatile as changes within ISR - g_ prefix makes it easier to distinguish it as global
legstar85 12:5046b7515d5c 77 volatile int g_ButtonB_flag = 0; // Flag - must be volatile as changes within ISR - g_ prefix makes it easier to distinguish it as global
legstar85 12:5046b7515d5c 78 volatile int g_ButtonBack_flag = 0; // Flag - must be volatile as changes within ISR - g_ prefix makes it easier to distinguish it as global
legstar85 12:5046b7515d5c 79 volatile int g_sw2_flag = 0; // Flag - must be volatile as changes within ISR - g_ prefix makes it easier to distinguish it as global
legstar85 12:5046b7515d5c 80 volatile int g_menu_timer_flag = 0; // Flag - must be volatile as changes within ISR - g_ prefix makes it easier to distinguish it as global
legstar85 5:eebd36a47049 81 volatile int option = 0; // Menu option selection based on joystick direction
legstar85 11:a6eec09b546e 82 volatile int g_state = 0; //
legstar85 11:a6eec09b546e 83 volatile int g_StartTemp = 0; //
legstar85 2:e0091b5311f1 84
legstar85 2:e0091b5311f1 85 void error(); // error function hangs flashing an LED
legstar85 2:e0091b5311f1 86 void init_serial(); // setup serial port
legstar85 2:e0091b5311f1 87 void init_K64F(); // set-up the on-board LEDs and switches
legstar85 3:80c1eba78f9b 88 void init_PCB(); // set-up the PCB LEDs and buttons
legstar85 9:d71b92c916f8 89 void ButtonA_isr(); //
legstar85 9:d71b92c916f8 90 void ButtonB_isr(); //
legstar85 9:d71b92c916f8 91 void ButtonBack_isr(); //
legstar85 9:d71b92c916f8 92 void sw2_isr(); //
legstar85 9:d71b92c916f8 93 void menu_timer_isr(); //
legstar85 6:ebf4784ce92b 94 void OnStartup(); //
legstar85 6:ebf4784ce92b 95 void Run(); //
legstar85 11:a6eec09b546e 96 void StartTemp(); //
legstar85 14:3e9991fe64e5 97 void delete_file(char filename[]); //
legstar85 14:3e9991fe64e5 98 void WriteToFile(); // Function to attempt to write temperature to file
eencae 0:21a200b880d7 99
eencae 0:21a200b880d7 100 int main()
eencae 0:21a200b880d7 101 {
legstar85 2:e0091b5311f1 102 init_K64F(); // initialise the board
legstar85 2:e0091b5311f1 103 init_serial(); // initialise the serial port
legstar85 3:80c1eba78f9b 104 init_PCB(); // initialise the PCB
legstar85 3:80c1eba78f9b 105
legstar85 2:e0091b5311f1 106 tmp102.init(); // call the sensor init method using dot syntax
legstar85 2:e0091b5311f1 107 lcd.init(); // initialise display
legstar85 3:80c1eba78f9b 108 joystick.init(); // initialise joystick
legstar85 3:80c1eba78f9b 109
legstar85 5:eebd36a47049 110 ticker_menu.attach(&menu_timer_isr,0.2); // Attach ticker for the Joystick
legstar85 5:eebd36a47049 111
legstar85 3:80c1eba78f9b 112 sw2.fall(&sw2_isr); // SW2 has a pull-up resistor, so the pin will be at 3.3 V by default and fall to 0 V when pressed. We therefore need to look for a falling edge on the pin to fire the interrupt
legstar85 3:80c1eba78f9b 113 ButtonA.rise(&ButtonA_isr); // External push button, pin set to 0V by pull down command, means a rising edge is looked for
legstar85 3:80c1eba78f9b 114 ButtonB.rise(&ButtonB_isr); // External push button, pin set to 0V by pull down command, means a rising edge is looked for
legstar85 2:e0091b5311f1 115
legstar85 2:e0091b5311f1 116 lcd.setContrast(0.5); // change set contrast in range 0.0 to 1.0
eencae 0:21a200b880d7 117
legstar85 11:a6eec09b546e 118 OnStartup(); // Call intro screen
legstar85 9:d71b92c916f8 119 Run(); // Call main-menu and functions
legstar85 5:eebd36a47049 120 }
eencae 0:21a200b880d7 121
eencae 0:21a200b880d7 122 void init_serial() {
legstar85 2:e0091b5311f1 123 pc.baud(115200); // set to highest baud - ensure terminal software matches
eencae 0:21a200b880d7 124 }
eencae 0:21a200b880d7 125
eencae 0:21a200b880d7 126 void init_K64F()
eencae 0:21a200b880d7 127 {
legstar85 2:e0091b5311f1 128 r_led = 1; // on-board LEDs are active-low, so set pin high to turn them off.
legstar85 2:e0091b5311f1 129 g_led = 1; // on-board LEDs are active-low, so set pin high to turn them off.
legstar85 2:e0091b5311f1 130 b_led = 1; // on-board LEDs are active-low, so set pin high to turn them off.
eencae 0:21a200b880d7 131
legstar85 2:e0091b5311f1 132 sw2.mode(PullNone); // since the on-board switches have external pull-ups, we should disable the internal pull-down
legstar85 2:e0091b5311f1 133 sw3.mode(PullNone); // resistors that are enabled by default using InterruptIn
eencae 0:21a200b880d7 134 }
legstar85 3:80c1eba78f9b 135
legstar85 3:80c1eba78f9b 136 void init_PCB ()
legstar85 3:80c1eba78f9b 137 {
legstar85 3:80c1eba78f9b 138 LED01 = 1; // PCB surface mounted LED's are active low - write a 1 to turn them off initiallly
legstar85 9:d71b92c916f8 139 LED02 = 1; // PCB surface mounted LED's are active low - write a 1 to turn them off initiallly
legstar85 9:d71b92c916f8 140 LED03 = 1; // PCB surface mounted LED's are active low - write a 1 to turn them off initiallly
legstar85 9:d71b92c916f8 141 LED04 = 1; // PCB surface mounted LED's are active low - write a 1 to turn them off initiallly
legstar85 9:d71b92c916f8 142 LED05 = 1; // PCB surface mounted LED's are active low - write a 1 to turn them off initiallly
legstar85 9:d71b92c916f8 143 LED06 = 1; // PCB surface mounted LED's are active low - write a 1 to turn them off initiallly
legstar85 9:d71b92c916f8 144
legstar85 9:d71b92c916f8 145 Buzzer = 0; // Ensure Piezo Buzzer is off
legstar85 3:80c1eba78f9b 146
legstar85 3:80c1eba78f9b 147 ButtonA.mode(PullDown); // Set pin to Pull Down to OV, meaning that a rising edge is looked for when button is pressed
legstar85 3:80c1eba78f9b 148 ButtonB.mode(PullDown); // Set pin to Pull Down to OV, meaning that a rising edge is looked for when button is pressed
legstar85 3:80c1eba78f9b 149 }
legstar85 3:80c1eba78f9b 150
legstar85 3:80c1eba78f9b 151 void ButtonA_isr() // ButtonA event-triggered interrupt
legstar85 3:80c1eba78f9b 152 {
legstar85 3:80c1eba78f9b 153 g_ButtonA_flag = 1; // set flag in ISR
legstar85 3:80c1eba78f9b 154 }
legstar85 3:80c1eba78f9b 155
legstar85 3:80c1eba78f9b 156 void ButtonB_isr() // ButtonB event-triggered interrupt
legstar85 3:80c1eba78f9b 157 {
legstar85 3:80c1eba78f9b 158 g_ButtonB_flag = 1; // set flag in ISR
legstar85 3:80c1eba78f9b 159 }
legstar85 3:80c1eba78f9b 160
legstar85 7:d77e95505e43 161 void ButtonBack_isr() // ButtonB event-triggered interrupt
legstar85 7:d77e95505e43 162 {
legstar85 7:d77e95505e43 163 g_ButtonBack_flag = 1; // set flag in ISR
legstar85 7:d77e95505e43 164 }
legstar85 7:d77e95505e43 165
legstar85 3:80c1eba78f9b 166 void sw2_isr() // SW2 event-triggered interrupt
legstar85 3:80c1eba78f9b 167 {
legstar85 3:80c1eba78f9b 168 g_sw2_flag = 1; // set flag in ISR
legstar85 5:eebd36a47049 169 }
legstar85 5:eebd36a47049 170
legstar85 5:eebd36a47049 171 void menu_timer_isr()
legstar85 5:eebd36a47049 172 {
legstar85 6:ebf4784ce92b 173 g_menu_timer_flag = 1; // set flag in ISR
legstar85 6:ebf4784ce92b 174 }
legstar85 6:ebf4784ce92b 175
legstar85 9:d71b92c916f8 176 void OnStartup() // Run some start up display
legstar85 6:ebf4784ce92b 177 {
legstar85 12:5046b7515d5c 178 Buzzer.period(1.0/659.0); // Welcome sounds from Piezo
legstar85 12:5046b7515d5c 179 Buzzer = 0.5; //
legstar85 12:5046b7515d5c 180 wait(0.5); //
legstar85 12:5046b7515d5c 181 Buzzer.period(1.0/494.0); //
legstar85 12:5046b7515d5c 182 Buzzer = 0.5; //
legstar85 12:5046b7515d5c 183 wait(0.5); //
legstar85 12:5046b7515d5c 184 Buzzer.period(1.0/554.0); //
legstar85 12:5046b7515d5c 185 Buzzer = 0.5; //
legstar85 12:5046b7515d5c 186 wait(0.5); //
legstar85 12:5046b7515d5c 187 Buzzer = 0; // Turn off welcome sounds
legstar85 9:d71b92c916f8 188 lcd.clear(); // Clear buffer at start of every loop
legstar85 9:d71b92c916f8 189 lcd.printString("--------------",0,0); // Can directly print strings at specified co-ordinates (must be less than 84 pixels to fit on display)
legstar85 7:d77e95505e43 190 lcd.printString(" Smart Cold",0,1); // Just a welcome message before auto moving to main menu
legstar85 7:d77e95505e43 191 lcd.printString(" Storage",0,2); //
legstar85 7:d77e95505e43 192 lcd.printString(" Monitoring",0,3); //
legstar85 14:3e9991fe64e5 193 lcd.printString("V15 - Jan 2022",0,4); //
legstar85 7:d77e95505e43 194 lcd.printString("--------------",0,5); //
legstar85 9:d71b92c916f8 195 lcd.refresh(); // Need to refresh display after setting pixels or writing strings
legstar85 9:d71b92c916f8 196 wait(5.0); // Leave welcome screen on for designated amount of time
legstar85 9:d71b92c916f8 197 lcd.clear(); // Clear buffer at start of every loop
legstar85 9:d71b92c916f8 198 lcd.refresh(); // Need to refresh display after setting pixels or writing strings
legstar85 8:07323fcab6d1 199 lcd.printString("--------------",0,0); //
legstar85 8:07323fcab6d1 200 lcd.printString(" Use Joystick",0,1); // Instruction for use of menu
legstar85 8:07323fcab6d1 201 lcd.printString(" To Navigate",0,2); //
legstar85 8:07323fcab6d1 202 lcd.printString("",0,3); // Blank Line
legstar85 8:07323fcab6d1 203 lcd.printString(" A = Select",0,4); //
legstar85 8:07323fcab6d1 204 lcd.printString("--------------",0,5); //
legstar85 9:d71b92c916f8 205 lcd.refresh(); // Need to refresh display after setting pixels or writing strings
legstar85 7:d77e95505e43 206 wait(5.0); //
legstar85 9:d71b92c916f8 207 init_PCB(); // Ran again to ensure all LED's etc are turned off
legstar85 13:5ad65a688f3f 208 printf("Transition to Temp Selection %i\n",StartTemp); // Observe on serial port - ensure transition to correct screen
legstar85 5:eebd36a47049 209 }
legstar85 5:eebd36a47049 210
legstar85 9:d71b92c916f8 211 enum EMenuState // An enum controlling the current state of the display.
legstar85 6:ebf4784ce92b 212 {
legstar85 12:5046b7515d5c 213 MENUSTATE_StartTemp, // Defining each menu state to be called upon later
legstar85 9:d71b92c916f8 214 MENUSTATE_Main, // Defining each menu state to be called upon later
legstar85 9:d71b92c916f8 215 MENUSTATE_Monitor, // Defining each menu state to be called upon later
legstar85 9:d71b92c916f8 216 MENUSTATE_OneOff, // Defining each menu state to be called upon later
legstar85 14:3e9991fe64e5 217 MENUSTATE_Results, // Defining each menu state to be called upon later
legstar85 9:d71b92c916f8 218 MENUSTATE_About, // Defining each menu state to be called upon later
legstar85 9:d71b92c916f8 219 MENUSTATE_Author, // Defining each menu state to be called upon later
legstar85 6:ebf4784ce92b 220
legstar85 6:ebf4784ce92b 221 MENUSTATTE_Num, // This is a special enum value that just gives is a way to get the number of elements in the enum.
legstar85 6:ebf4784ce92b 222 };
legstar85 6:ebf4784ce92b 223
legstar85 6:ebf4784ce92b 224 void Run()
legstar85 5:eebd36a47049 225 {
legstar85 13:5ad65a688f3f 226 int MenuState = MENUSTATE_StartTemp; //
legstar85 9:d71b92c916f8 227 int SelectedItem = 0; //
legstar85 9:d71b92c916f8 228 int NumMenuItems = 1; //
legstar85 6:ebf4784ce92b 229
legstar85 7:d77e95505e43 230 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
legstar85 7:d77e95505e43 231
legstar85 6:ebf4784ce92b 232 while(1){
legstar85 9:d71b92c916f8 233 if (g_menu_timer_flag){ //
legstar85 9:d71b92c916f8 234 g_menu_timer_flag = 0; //
legstar85 5:eebd36a47049 235
legstar85 6:ebf4784ce92b 236 bool bAButtonWasPressed = g_ButtonA_flag; // Get the value of the input flags and reset them
legstar85 9:d71b92c916f8 237 bool bBButtonWasPressed = g_ButtonB_flag; // Get the value of the input flags and reset them
legstar85 9:d71b92c916f8 238 g_ButtonA_flag = 0; //
legstar85 9:d71b92c916f8 239 g_ButtonB_flag = 0; //
legstar85 6:ebf4784ce92b 240
legstar85 5:eebd36a47049 241 lcd.clear(); // clear buffer at start of every loop
legstar85 6:ebf4784ce92b 242
legstar85 6:ebf4784ce92b 243 int NewMenuState = MENUSTATTE_Num; // The new menu we want to transition to, if any.
legstar85 6:ebf4784ce92b 244
legstar85 6:ebf4784ce92b 245 switch(MenuState) // Update and Draw whichever menu we're on.
legstar85 11:a6eec09b546e 246 {
legstar85 12:5046b7515d5c 247 case MENUSTATE_StartTemp: //
legstar85 13:5ad65a688f3f 248 {
legstar85 11:a6eec09b546e 249 NumMenuItems = 1; // Dont for get to set this when changing number of items in the menu. We need this to wrap the selection around properly etc.
legstar85 11:a6eec09b546e 250 if(SelectedItem >= NumMenuItems) //
legstar85 11:a6eec09b546e 251 {
legstar85 11:a6eec09b546e 252 SelectedItem = 0; // Something has gone wrong, reset selected item.
legstar85 11:a6eec09b546e 253 }
legstar85 12:5046b7515d5c 254 Direction d = joystick.get_direction();
legstar85 11:a6eec09b546e 255
legstar85 11:a6eec09b546e 256 StartTemp();
legstar85 11:a6eec09b546e 257
legstar85 11:a6eec09b546e 258 float g_StartTemp = fsm[g_state].output; // read temperature and print to lcd
legstar85 12:5046b7515d5c 259 pc.printf("T = %f C\n",g_StartTemp); // Print to serial - allows testing without device attached
legstar85 11:a6eec09b546e 260 printf ("Joystick Direction Points = %i\n",d); //
legstar85 12:5046b7515d5c 261 printf ("State selected = %i\n", g_state); //
legstar85 11:a6eec09b546e 262 int length = sprintf(buffer," T = %.2f C",g_StartTemp); // print formatted data to buffer - it is important the format specifier ensures the length will fit in the buffer
legstar85 13:5ad65a688f3f 263 if (length <= 14){ // if string will fit on display (assuming printing at x=0)
legstar85 13:5ad65a688f3f 264 lcd.printString("- Set Target -",0,0); //
legstar85 13:5ad65a688f3f 265 lcd.printString("---- Temp ----",0,1); //
legstar85 13:5ad65a688f3f 266 lcd.printString(buffer,0,3); // display on screen
legstar85 13:5ad65a688f3f 267 lcd.printString("'A' to Select",0,5); //
legstar85 13:5ad65a688f3f 268 lcd.refresh();
legstar85 13:5ad65a688f3f 269 } // need to refresh display after setting pixels or writing strings
legstar85 12:5046b7515d5c 270
legstar85 11:a6eec09b546e 271 if(bAButtonWasPressed) // If A was pressed then we transition to the selected screen.
legstar85 11:a6eec09b546e 272 {
legstar85 11:a6eec09b546e 273 if(SelectedItem == 0) // If 0 line is selected, move to detailed menu
legstar85 11:a6eec09b546e 274 { // Actually 0 line + 1, see circle draw and selection below
legstar85 11:a6eec09b546e 275 NewMenuState = MENUSTATE_Main; //
legstar85 11:a6eec09b546e 276 }
legstar85 11:a6eec09b546e 277 }
legstar85 11:a6eec09b546e 278 }
legstar85 11:a6eec09b546e 279 break; //
legstar85 9:d71b92c916f8 280 case MENUSTATE_Main: //
legstar85 6:ebf4784ce92b 281 {
legstar85 14:3e9991fe64e5 282 NumMenuItems = 5; // Dont for get to set this when changing number of items in the menu. We need this to wrap the selection around properly etc.
legstar85 9:d71b92c916f8 283 if(SelectedItem >= NumMenuItems) //
legstar85 6:ebf4784ce92b 284 {
legstar85 6:ebf4784ce92b 285 SelectedItem = 0; // Something has gone wrong, reset selected item.
legstar85 6:ebf4784ce92b 286 }
legstar85 9:d71b92c916f8 287 lcd.printString("---- MENU ----",0,0); // Menu title and selectable options
legstar85 9:d71b92c916f8 288 lcd.printString("M1 - Monitor",0,1); // Printed to the LCD screen
legstar85 9:d71b92c916f8 289 lcd.printString("M2 - One-off",0,2); //
legstar85 14:3e9991fe64e5 290 lcd.printString("Results",0,3); //
legstar85 14:3e9991fe64e5 291 lcd.printString("About",0,4); //
legstar85 14:3e9991fe64e5 292 lcd.printString("Author",0,5); //
legstar85 6:ebf4784ce92b 293
legstar85 6:ebf4784ce92b 294 if(bAButtonWasPressed) // If A was pressed then we transition to the selected screen.
legstar85 6:ebf4784ce92b 295 {
legstar85 8:07323fcab6d1 296 if(SelectedItem == 0) // If 0 line is selected, move to detailed menu
legstar85 8:07323fcab6d1 297 { // Actually 0 line + 1, see circle draw and selection below
legstar85 9:d71b92c916f8 298 NewMenuState = MENUSTATE_Monitor; //
legstar85 6:ebf4784ce92b 299 }
legstar85 8:07323fcab6d1 300 else if(SelectedItem == 1) // If 1 line is selected, move to detailed menu
legstar85 8:07323fcab6d1 301 { // Actually 1 line + 1, see circle draw and selection below
legstar85 9:d71b92c916f8 302 NewMenuState = MENUSTATE_OneOff; //
legstar85 6:ebf4784ce92b 303 }
legstar85 8:07323fcab6d1 304 else if(SelectedItem == 2) // If 2 line is selected, move to detailed menu
legstar85 8:07323fcab6d1 305 { // Actually 2 line + 1, see circle draw and selection below
legstar85 14:3e9991fe64e5 306 NewMenuState = MENUSTATE_Results; //
legstar85 14:3e9991fe64e5 307 }
legstar85 14:3e9991fe64e5 308 else if(SelectedItem == 3) // If 2 line is selected, move to detailed menu
legstar85 14:3e9991fe64e5 309 { // Actually 2 line + 1, see circle draw and selection below
legstar85 9:d71b92c916f8 310 NewMenuState = MENUSTATE_About; //
legstar85 6:ebf4784ce92b 311 }
legstar85 14:3e9991fe64e5 312 else if(SelectedItem == 4) // If 3 line is selected, move to detailed menu
legstar85 8:07323fcab6d1 313 { // Actually 3 line + 1, see circle draw and selection below
legstar85 9:d71b92c916f8 314 NewMenuState = MENUSTATE_Author; //
legstar85 7:d77e95505e43 315 }
legstar85 6:ebf4784ce92b 316 }
legstar85 6:ebf4784ce92b 317 }
legstar85 9:d71b92c916f8 318 break; //
legstar85 9:d71b92c916f8 319 case MENUSTATE_Monitor: // Call constant measurement menu following top menu selection
legstar85 6:ebf4784ce92b 320 {
legstar85 8:07323fcab6d1 321 NumMenuItems = 1; // Detail the number of items in Menu - need this to wrap the selection around properly etc.
legstar85 6:ebf4784ce92b 322
legstar85 9:d71b92c916f8 323 if(SelectedItem >= NumMenuItems) //
legstar85 6:ebf4784ce92b 324 {
legstar85 6:ebf4784ce92b 325 NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
legstar85 6:ebf4784ce92b 326 }
legstar85 6:ebf4784ce92b 327
legstar85 7:d77e95505e43 328 float T = tmp102.get_temperature(); // read temperature and print to lcd
legstar85 9:d71b92c916f8 329 pc.printf("T = %f K\n",T); // Print to serial - allows testing without device attached
legstar85 7:d77e95505e43 330 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
legstar85 7:d77e95505e43 331 if (length <= 14) // if string will fit on display (assuming printing at x=0)
legstar85 9:d71b92c916f8 332 lcd.printString("-- Constant --",0,0); //
legstar85 9:d71b92c916f8 333 lcd.printString("- Monitoring -",0,1); //
legstar85 7:d77e95505e43 334 lcd.printString(buffer,0,3); // display on screen
legstar85 9:d71b92c916f8 335 lcd.printString(" 'A' to Menu",0,5); //
legstar85 7:d77e95505e43 336 lcd.refresh(); // need to refresh display after setting pixels or writing strings
legstar85 9:d71b92c916f8 337 wait(0.5); //
legstar85 8:07323fcab6d1 338
legstar85 13:5ad65a688f3f 339 if (T >= g_StartTemp + 2) { // High temp alarm condition - in real world would be lot lower!!
legstar85 13:5ad65a688f3f 340 LED01 = !LED01; // Flash LED01 if temperature is over specified - Simulated starting of cold blowers
legstar85 13:5ad65a688f3f 341 LED02 = !LED02; // Flash LED02 if temperature is over specified - Simulated starting of cold blowers
legstar85 13:5ad65a688f3f 342 LED03 = !LED03; // Flash LED03 if temperature is over specified - Simulated starting of cold blowers
legstar85 13:5ad65a688f3f 343 printf("WARNING - High Temp!! \n"); //
legstar85 13:5ad65a688f3f 344 Buzzer.period(1.0/554.0); // Warning Buzzer to extremely high
legstar85 13:5ad65a688f3f 345 Buzzer = 0.5; //
legstar85 13:5ad65a688f3f 346 wait(0.5); //
legstar85 13:5ad65a688f3f 347 Buzzer = 0; //
legstar85 8:07323fcab6d1 348 }
legstar85 13:5ad65a688f3f 349 else {
legstar85 9:d71b92c916f8 350 LED01 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
legstar85 9:d71b92c916f8 351 LED02 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
legstar85 9:d71b92c916f8 352 LED03 = 1; // LED01 off if temperature is below specified - Simulated stopping of cold blowers
legstar85 13:5ad65a688f3f 353 Buzzer = 0; // Buzzer off if temperature is below specified - Simulated stopping of cold blowers
legstar85 9:d71b92c916f8 354 }
legstar85 9:d71b92c916f8 355
legstar85 13:5ad65a688f3f 356 if (T <= g_StartTemp - 2) { // High temp alarm condition - in real world would be lot lower!!
legstar85 14:3e9991fe64e5 357 LED04 = !LED04; // Flash LED01 if temperature is over specified - Simulated starting of heaters
legstar85 14:3e9991fe64e5 358 LED05 = !LED05; // Flash LED02 if temperature is over specified - Simulated starting of heaters
legstar85 14:3e9991fe64e5 359 LED06 = !LED06; // Flash LED03 if temperature is over specified - Simulated starting of heaters
legstar85 13:5ad65a688f3f 360 printf("WARNING - Low Temp!! \n"); //
legstar85 13:5ad65a688f3f 361 Buzzer.period(1.0/554.0); // Warning Buzzer to extremely high
legstar85 13:5ad65a688f3f 362 Buzzer = 0.5; //
legstar85 13:5ad65a688f3f 363 wait(0.5); //
legstar85 13:5ad65a688f3f 364 Buzzer = 0; //
legstar85 9:d71b92c916f8 365 }
legstar85 13:5ad65a688f3f 366 else {
legstar85 14:3e9991fe64e5 367 LED04 = 1; // LED01 off if temperature is below specified - Simulated stopping of heaters
legstar85 14:3e9991fe64e5 368 LED05 = 1; // LED01 off if temperature is below specified - Simulated stopping of heaters
legstar85 14:3e9991fe64e5 369 LED06 = 1; // LED01 off if temperature is below specified - Simulated stopping of heaters
legstar85 14:3e9991fe64e5 370 Buzzer = 0; // Buzzer off if temperature is below specified - Simulated stopping of heaters
legstar85 8:07323fcab6d1 371 }
legstar85 9:d71b92c916f8 372 if(bAButtonWasPressed) // Check if button was pressed
legstar85 6:ebf4784ce92b 373 {
legstar85 9:d71b92c916f8 374 if(SelectedItem == 0) //
legstar85 6:ebf4784ce92b 375 {
legstar85 9:d71b92c916f8 376 NewMenuState = MENUSTATE_Main; // Transition back to the main menu
legstar85 9:d71b92c916f8 377 LED01 = 1; // Turn off LED upon transition back to main menu
legstar85 9:d71b92c916f8 378 LED02 = 1; // Turn off LED upon transition back to main menu
legstar85 9:d71b92c916f8 379 LED03 = 1; // Turn off LED upon transition back to main menu
legstar85 9:d71b92c916f8 380 LED04 = 1; // Turn off LED upon transition back to main menu
legstar85 9:d71b92c916f8 381 LED05 = 1; // Turn off LED upon transition back to main menu
legstar85 9:d71b92c916f8 382 LED06 = 1; // Turn off LED upon transition back to main menu
legstar85 6:ebf4784ce92b 383 }
legstar85 6:ebf4784ce92b 384 }
legstar85 6:ebf4784ce92b 385 }
legstar85 6:ebf4784ce92b 386 break;
legstar85 11:a6eec09b546e 387 case MENUSTATE_OneOff: // Call a one off measurement menu following top menu selection
legstar85 6:ebf4784ce92b 388 {
legstar85 8:07323fcab6d1 389 NumMenuItems = 1; // Detail the number of items in Menu - need this to wrap the selection around properly etc.
legstar85 9:d71b92c916f8 390 if(SelectedItem >= NumMenuItems) //
legstar85 6:ebf4784ce92b 391 {
legstar85 7:d77e95505e43 392 NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
legstar85 6:ebf4784ce92b 393 }
legstar85 6:ebf4784ce92b 394
legstar85 14:3e9991fe64e5 395 T = tmp102.get_temperature(); // read temperature and print to lcd
legstar85 9:d71b92c916f8 396 pc.printf("T = %f K\n",T); // Print to serial - allows testing without device attached
legstar85 8:07323fcab6d1 397 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
legstar85 14:3e9991fe64e5 398 if (length <= 14){ // if string will fit on display (assuming printing at x=0)
legstar85 14:3e9991fe64e5 399 lcd.printString("-- One-Off --",0,0); //
legstar85 14:3e9991fe64e5 400 lcd.printString("-- Measure --",0,1); //
legstar85 14:3e9991fe64e5 401 lcd.printString(buffer,0,3); // display on screen
legstar85 14:3e9991fe64e5 402 lcd.printString(" 'A' to Menu",0,5); //
legstar85 13:5ad65a688f3f 403 }
legstar85 6:ebf4784ce92b 404
legstar85 9:d71b92c916f8 405 if(bAButtonWasPressed) // Check if button was pressed
legstar85 6:ebf4784ce92b 406 {
legstar85 9:d71b92c916f8 407 if(SelectedItem == 0) //
legstar85 6:ebf4784ce92b 408 {
legstar85 8:07323fcab6d1 409 NewMenuState = MENUSTATE_Main; // Take us back to top menu
legstar85 6:ebf4784ce92b 410 }
legstar85 6:ebf4784ce92b 411 }
legstar85 6:ebf4784ce92b 412
legstar85 6:ebf4784ce92b 413 }
legstar85 14:3e9991fe64e5 414 break;
legstar85 14:3e9991fe64e5 415 case MENUSTATE_Results: // Call Author menu following top menu selection
legstar85 14:3e9991fe64e5 416 {
legstar85 14:3e9991fe64e5 417
legstar85 14:3e9991fe64e5 418 NumMenuItems = 1; // Detail the number of items in Menu - need this to wrap the selection around properly etc.
legstar85 14:3e9991fe64e5 419 if(SelectedItem >= NumMenuItems) //
legstar85 14:3e9991fe64e5 420 {
legstar85 14:3e9991fe64e5 421 NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
legstar85 14:3e9991fe64e5 422 }
legstar85 14:3e9991fe64e5 423
legstar85 14:3e9991fe64e5 424 WriteToFile(); //
legstar85 14:3e9991fe64e5 425
legstar85 14:3e9991fe64e5 426 lcd.printString("--- Results ---",0,0); //
legstar85 14:3e9991fe64e5 427 lcd.printString(" ",0,1); //
legstar85 14:3e9991fe64e5 428 lcd.printString(" ",0,2); //
legstar85 14:3e9991fe64e5 429 lcd.printString(" ",0,3); //
legstar85 14:3e9991fe64e5 430 lcd.printString(" ",0,4); //
legstar85 14:3e9991fe64e5 431 lcd.printString(" 'A' to Menu",0,5); //
legstar85 14:3e9991fe64e5 432
legstar85 14:3e9991fe64e5 433 if(bAButtonWasPressed) // Check if button was pressed
legstar85 14:3e9991fe64e5 434 {
legstar85 14:3e9991fe64e5 435 if(SelectedItem == 0) //
legstar85 14:3e9991fe64e5 436 {
legstar85 14:3e9991fe64e5 437 NewMenuState = MENUSTATE_Main; // Take us back to top menu
legstar85 14:3e9991fe64e5 438 }
legstar85 14:3e9991fe64e5 439 }
legstar85 14:3e9991fe64e5 440 }
legstar85 14:3e9991fe64e5 441 break;
legstar85 9:d71b92c916f8 442 case MENUSTATE_About: // Call About menu following top menu selection
legstar85 6:ebf4784ce92b 443 {
legstar85 8:07323fcab6d1 444 NumMenuItems = 1; // Detail the number of items in Menu - need this to wrap the selection around properly etc.
legstar85 9:d71b92c916f8 445 if(SelectedItem >= NumMenuItems) //
legstar85 6:ebf4784ce92b 446 {
legstar85 6:ebf4784ce92b 447 NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
legstar85 6:ebf4784ce92b 448 }
legstar85 6:ebf4784ce92b 449
legstar85 9:d71b92c916f8 450 lcd.printString("--- About ---",0,0); //
legstar85 9:d71b92c916f8 451 lcd.printString("ELE3006M - IoT",0,1); //
legstar85 9:d71b92c916f8 452 lcd.printString(" Project",0,2); //
legstar85 9:d71b92c916f8 453 lcd.printString("Uni of Lincoln",0,3); //
legstar85 9:d71b92c916f8 454 lcd.printString(" 'A' to Menu",0,5); //
legstar85 9:d71b92c916f8 455 lcd.refresh(); //
legstar85 6:ebf4784ce92b 456
legstar85 9:d71b92c916f8 457 if(bAButtonWasPressed) // Check if button was pressed
legstar85 6:ebf4784ce92b 458 {
legstar85 9:d71b92c916f8 459 if(SelectedItem == 0) //
legstar85 6:ebf4784ce92b 460 {
legstar85 9:d71b92c916f8 461 NewMenuState = MENUSTATE_Main; // Transition back to Main Menu
legstar85 6:ebf4784ce92b 462 }
legstar85 6:ebf4784ce92b 463 }
legstar85 6:ebf4784ce92b 464 }
legstar85 6:ebf4784ce92b 465 break;
legstar85 9:d71b92c916f8 466 case MENUSTATE_Author: // Call Author menu following top menu selection
legstar85 7:d77e95505e43 467 {
legstar85 7:d77e95505e43 468
legstar85 8:07323fcab6d1 469 NumMenuItems = 1; // Detail the number of items in Menu - need this to wrap the selection around properly etc.
legstar85 9:d71b92c916f8 470 if(SelectedItem >= NumMenuItems) //
legstar85 7:d77e95505e43 471 {
legstar85 7:d77e95505e43 472 NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
legstar85 7:d77e95505e43 473 }
legstar85 7:d77e95505e43 474
legstar85 9:d71b92c916f8 475 lcd.printString("--- Author ---",0,0); //
legstar85 9:d71b92c916f8 476 lcd.printString("David Leaming ",0,1); //
legstar85 9:d71b92c916f8 477 lcd.printString(" 25574043 ",0,2); //
legstar85 9:d71b92c916f8 478 lcd.printString(" VolkerRail",0,3); //
legstar85 9:d71b92c916f8 479 lcd.printString(" 'A' to Menu",0,5); //
legstar85 7:d77e95505e43 480
legstar85 9:d71b92c916f8 481 if(bAButtonWasPressed) // Check if button was pressed
legstar85 7:d77e95505e43 482 {
legstar85 9:d71b92c916f8 483 if(SelectedItem == 0) //
legstar85 7:d77e95505e43 484 {
legstar85 8:07323fcab6d1 485 NewMenuState = MENUSTATE_Main; // Take us back to top menu
legstar85 7:d77e95505e43 486 }
legstar85 7:d77e95505e43 487 }
legstar85 7:d77e95505e43 488 }
legstar85 7:d77e95505e43 489 break;
legstar85 7:d77e95505e43 490
legstar85 6:ebf4784ce92b 491 default:
legstar85 6:ebf4784ce92b 492 {
legstar85 6:ebf4784ce92b 493 NewMenuState = MENUSTATE_Main; // Something has gone wrong, drop back to the main menu.
legstar85 6:ebf4784ce92b 494 }
legstar85 6:ebf4784ce92b 495 };
legstar85 5:eebd36a47049 496
legstar85 6:ebf4784ce92b 497 if(NewMenuState != MENUSTATTE_Num) // If we have requested a new menu state.
legstar85 6:ebf4784ce92b 498 {
legstar85 8:07323fcab6d1 499 printf("Transitioning to MenuState: %i\n", NewMenuState); // Observe on serial port - ensure transition to correct screen
legstar85 6:ebf4784ce92b 500
legstar85 6:ebf4784ce92b 501 MenuState = NewMenuState; // We want to transition the menu to a new state.
legstar85 6:ebf4784ce92b 502
legstar85 6:ebf4784ce92b 503 // Do any bookkeeping needed when moving to new state.
legstar85 6:ebf4784ce92b 504 SelectedItem = 0; // Reset the selected item.
legstar85 6:ebf4784ce92b 505
legstar85 6:ebf4784ce92b 506 lcd.clear(); // Clear the display for one frame on state transition.
legstar85 11:a6eec09b546e 507 }
legstar85 6:ebf4784ce92b 508 else
legstar85 6:ebf4784ce92b 509 {
legstar85 13:5ad65a688f3f 510 unsigned int SelectionMarkerRadius = 4; // If we have not selected to move to a new menu.
legstar85 13:5ad65a688f3f 511 unsigned int SelectionMarkerX = WIDTH - (2 * SelectionMarkerRadius); // Draw a marker circle at end of line to show which is the currently selected item.
legstar85 13:5ad65a688f3f 512 unsigned int SelectionMarkerY = (HEIGHT / 5) * (SelectedItem + 1); // +1 because of the menu title being on first row
legstar85 13:5ad65a688f3f 513 lcd.drawCircle(SelectionMarkerX, SelectionMarkerY, SelectionMarkerRadius, FILL_BLACK); // Fill the circle black so it can be seen easily
legstar85 6:ebf4784ce92b 514
legstar85 6:ebf4784ce92b 515 // Handle Joystick Input
legstar85 13:5ad65a688f3f 516 Direction d = joystick.get_direction();
legstar85 13:5ad65a688f3f 517 printf("Direction = %i\n");
legstar85 13:5ad65a688f3f 518 switch (joystick.get_direction()) { // Call to check direction joystick is pointing
legstar85 13:5ad65a688f3f 519 case N:
legstar85 13:5ad65a688f3f 520 {
legstar85 13:5ad65a688f3f 521 SelectedItem--;
legstar85 13:5ad65a688f3f 522 printf("Selection decremented to %i\n", SelectedItem);
legstar85 13:5ad65a688f3f 523 }
legstar85 6:ebf4784ce92b 524 break; //
legstar85 13:5ad65a688f3f 525 case S:
legstar85 13:5ad65a688f3f 526 {
legstar85 13:5ad65a688f3f 527 SelectedItem++;
legstar85 13:5ad65a688f3f 528 printf("Selection incremented to %i\n", SelectedItem);
legstar85 13:5ad65a688f3f 529 }
legstar85 6:ebf4784ce92b 530 break; //
legstar85 6:ebf4784ce92b 531 }
legstar85 6:ebf4784ce92b 532
legstar85 9:d71b92c916f8 533 if(SelectedItem < 0) // Wrap the selection around to the start/end of the menu if it goes below 0 or above NumMenuItems.
legstar85 6:ebf4784ce92b 534 {
legstar85 9:d71b92c916f8 535 SelectedItem = NumMenuItems - 1; //
legstar85 6:ebf4784ce92b 536 }
legstar85 9:d71b92c916f8 537 else if(SelectedItem >= NumMenuItems) //
legstar85 6:ebf4784ce92b 538 {
legstar85 9:d71b92c916f8 539 SelectedItem = 0; //
legstar85 6:ebf4784ce92b 540 }
legstar85 5:eebd36a47049 541 }
legstar85 5:eebd36a47049 542
legstar85 6:ebf4784ce92b 543 lcd.refresh(); //Finally update the display.
legstar85 6:ebf4784ce92b 544 }
legstar85 6:ebf4784ce92b 545 }
legstar85 5:eebd36a47049 546 }
legstar85 5:eebd36a47049 547
legstar85 11:a6eec09b546e 548 void StartTemp() //
legstar85 11:a6eec09b546e 549 {
legstar85 11:a6eec09b546e 550 Direction d = joystick.get_direction(); //
legstar85 12:5046b7515d5c 551
legstar85 11:a6eec09b546e 552 g_StartTemp = fsm[g_state].output; // set ouput depending on current state
legstar85 11:a6eec09b546e 553 wait(fsm[g_state].time); // wait in that state for desired time
legstar85 11:a6eec09b546e 554 g_state = fsm[g_state].nextState[d]; // read input and update curent state
legstar85 11:a6eec09b546e 555 }
legstar85 13:5ad65a688f3f 556
legstar85 14:3e9991fe64e5 557 void WriteToFile() // Function to attempt to write temperature to file
legstar85 14:3e9991fe64e5 558 {
legstar85 14:3e9991fe64e5 559 printf("#### SD Card Example #####\n");
legstar85 14:3e9991fe64e5 560 FILE *fp; // this is our file pointer
legstar85 14:3e9991fe64e5 561
legstar85 14:3e9991fe64e5 562 float T = tmp102.get_temperature(); // read temperature and print to lcd
legstar85 14:3e9991fe64e5 563 pc.printf("T = %f K\n",T); // Print to serial - allows testing without device attached
legstar85 14:3e9991fe64e5 564
legstar85 14:3e9991fe64e5 565 fp = fopen("OvernightTemps", "w");
legstar85 14:3e9991fe64e5 566 int ONight_Temp = T; //
legstar85 14:3e9991fe64e5 567
legstar85 14:3e9991fe64e5 568 if (fp == NULL) { // if it can't open the file then print error message
legstar85 14:3e9991fe64e5 569 printf("Error! Unable to open file!\n");
legstar85 14:3e9991fe64e5 570 }
legstar85 14:3e9991fe64e5 571 else { // opened file so can write
legstar85 14:3e9991fe64e5 572 printf("Writing to file....");
legstar85 14:3e9991fe64e5 573 for(int i = T; i <= 50; i++) {
legstar85 14:3e9991fe64e5 574 float T = 1000.0F/i; // dummy variable
legstar85 14:3e9991fe64e5 575 fprintf(fp, "%d,%f\n",i,T); // print formatted string to file (CSV)
legstar85 14:3e9991fe64e5 576 }
legstar85 14:3e9991fe64e5 577 printf("Done.\n");
legstar85 14:3e9991fe64e5 578 fclose(fp); // ensure you close the file after writing
legstar85 14:3e9991fe64e5 579 }
legstar85 14:3e9991fe64e5 580 }