Page 218 - ARM Based Microcontroller Projects Using MBED
P. 218
204 8. INTERMEDIATE LEVEL PROJECTS
double mV, T;
float MaxTemp, MinTemp;
clrscr(); // Clear the screen
homescr(); // Home teh cursor
MyPC.printf("\n\rDIGITAL THERMOSTAT"); // Heading
MyPC.printf("\n\r==================");
//
// Read the desired Max and Min temperatures
//
MyPC.printf("\n\rEnter Max Temperature : ");
MyPC.scanf("%f", &MaxTemp);
MyPC.printf("\n\rEnter Min Temperature : ");
MyPC.scanf("%f", &MinTemp);
//
// Read and convert the temperature into Degrees C. Set the alarm
// conditions if the temperature measured is low or high
//
while(1) // Do forever
{
mV = 3300.0f * ain.read(); // In mV
T = (mV - 500.0f) / 10.0f; // In Degrees C
gotoscr('7', '0'); // Line 7 col 0
if(T < MaxTemp && T > MinTemp) // If normal
{
MyPC.printf("NORMAL TEMPERATURE = ");
MyLED = 0; // LED OFF
}
else if(T >= MaxTemp) // If above
{
MyPC.printf("ALARM-HIGH TEMPERATURE = ");
MyLED = 1; // LED ON
}
else if(T <= MinTemp) // If below
{
MyPC.printf("ALARM-LOW TEMPERATURE = ");
MyLED = 1; // LED ON
}
MyPC.printf("%5.2f", T); // Display T
wait(1.0); // Wait 1 second
}
}
FIG. 8.68, CONT’D
and converted into degree Centigrade. The temperature is compared with the desired values
and appropriate messages are displayed on the PC screen. In addition, the current reading of
the temperature is displayed as a floating point number in the format %5.2f, which displays
the data as nn nn. The User LED is turned ON if the temperature is below or above the de-
sired values (Figs. 8.69 and 8.70).