Page 217 - ARM Based Microcontroller Projects Using MBED
P. 217

8.22  PROJECT 18—DIGITAL THERMOSTAT                203
                /*************************************************************************

                                            DIGITAL THERMOSTAT
                                            ==================
                This is a digital thermostat program. The user enters the desired Max
                and Min temperatures from the keyboard. The program measures the ambient
                temperature every second. If the temperature is above the Max value then
                the message ALARM-HIGH TEMPERATURE is displayed and the User LED is lit.
                Also, if the temperature is below the Min value then the message ALARM-
                LOW TEMPERATURE is displayed and the LED is lit to indicate the alarm
                condition. If the temperature is within the desired limits then the
                message MORMAL TEMPERATURE is displayed and the LED is turned OFF.
                Author: Dogan Ibrahim
                Date  : August 2018
                File  : Thermostat
                **************************************************************************/
                #include "mbed.h"
                Serial MyPC(USBTX, USBRX);
                AnalogIn ain(PA_0);
                DigitalOut MyLED(LED1);
                // Clear the screen
                //
                void clrscr()
                {
                    char clrscr[] = {0x1B, '[', '2' , 'J',0};
                    MyPC.printf(clrscr);
                }

                //
                // Home the cursor
                //
                void homescr()
                {
                    char homescr[] = {0x1B, '[' , 'H' , 0};
                    MyPC.printf(homescr);
                }
                //
                // Goto specified line and column
                //
                void gotoscr(int line, int column)
                {
                    char scr[] = {0x1B, '[', 0x00, ';' ,0x00, 'H', 0};
                    scr[2] = line;
                    scr[4] = column;
                    MyPC.printf(scr);
                }

                int main()
                {

            FIG. 8.68  Program listing.
                                                                                     (Continued)
   212   213   214   215   216   217   218   219   220   221   222