Page 224 - ARM Based Microcontroller Projects Using MBED
P. 224
double mV, T;
float SetPoint;
clrscr(); // Clear the screen
homescr(); // Home the cursor
MyPC.printf("\n\rON/OFF TEMPERATURE CONTROLLER"); // Display heading
//
// Read the desired Set-Point temperature
//
MyPC.printf("\n\rEnter the Desired Set-Point Temperature : ");
MyPC.scanf("%f", &SetPoint);
//
// Read and convert the temperature into Degrees C. Display the
// Set-Point and the measured temperatures. If the measured value
// is greater than the Set-Point then turn OFF the relay. If on the
// other hand the measured value is lower than the Set-Point then
// turn ON the relay
//
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
MyPC.printf("Set-Point Temperature = %5.2f", SetPoint);
MyPC.printf("\n\rMeasured Temperature = %5.2f", T);
if(T < SetPoint) // If higher
{
Relay = 1; // Relay ON
MyPC.printf("\n\rRELAY IS ON ");
}
else if(T > SetPoint)
{
Relay = 0;
MyPC.printf("\n\rRELAY IS OFF");
}
wait(1.0); // Wait 1 second
}
}
FIG. 8.75, CONT’D
FIG. 8.76 Typical run of the program.