for use with NXP LPC1768 Microcontroller mbed application board. The programme Reads the LM75B sensor temperature and Pot1 analogue input as room temp and thermostat temp setting respectively. Displays the temp and thermostat readings on LCD display and switches LED 1,2 and 4 on and off to indicated too hot, too cold and heater on or off.
Dependencies: C12832_lcd LM75B mbed
main.cpp@1:4a768c18e543, 2013-12-29 (annotated)
- Committer:
- rostam
- Date:
- Sun Dec 29 16:58:06 2013 +0000
- Revision:
- 1:4a768c18e543
- Parent:
- 0:b818a72ebb42
Comments added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rostam | 1:4a768c18e543 | 1 | //heater control using LM75B Temp sensor and Pot1 as inputs and LED1 and 2 as too hot and too cold tempreture indicators. |
rostam | 1:4a768c18e543 | 2 | //LED 4 is used to indicate heater on/off |
rostam | 1:4a768c18e543 | 3 | |
rostam | 0:b818a72ebb42 | 4 | #include "mbed.h" |
rostam | 0:b818a72ebb42 | 5 | #include "C12832_lcd.h" |
rostam | 0:b818a72ebb42 | 6 | #include "LM75B.h" |
rostam | 0:b818a72ebb42 | 7 | |
rostam | 0:b818a72ebb42 | 8 | DigitalOut toohot(LED1); |
rostam | 0:b818a72ebb42 | 9 | DigitalOut toocold(LED2); |
rostam | 0:b818a72ebb42 | 10 | DigitalOut heater(LED4); |
rostam | 0:b818a72ebb42 | 11 | |
rostam | 0:b818a72ebb42 | 12 | C12832_LCD disp; |
rostam | 0:b818a72ebb42 | 13 | LM75B temp(p28,p27); |
rostam | 0:b818a72ebb42 | 14 | AnalogIn therm(p19); |
rostam | 0:b818a72ebb42 | 15 | |
rostam | 0:b818a72ebb42 | 16 | float room_temp; |
rostam | 0:b818a72ebb42 | 17 | float therm_set; |
rostam | 0:b818a72ebb42 | 18 | |
rostam | 0:b818a72ebb42 | 19 | int main() |
rostam | 0:b818a72ebb42 | 20 | { |
rostam | 0:b818a72ebb42 | 21 | toocold=0; |
rostam | 0:b818a72ebb42 | 22 | toohot=0; |
rostam | 0:b818a72ebb42 | 23 | |
rostam | 0:b818a72ebb42 | 24 | while(1) |
rostam | 0:b818a72ebb42 | 25 | { |
rostam | 0:b818a72ebb42 | 26 | |
rostam | 1:4a768c18e543 | 27 | therm_set=therm.read() *45.0f;// Reading and caliberating the thermostat setting |
rostam | 0:b818a72ebb42 | 28 | room_temp=temp.read(); |
rostam | 1:4a768c18e543 | 29 | disp.cls(); // clear the screen |
rostam | 0:b818a72ebb42 | 30 | disp.locate(0,0); |
rostam | 0:b818a72ebb42 | 31 | disp.printf("Thermostat setting: %.2fc", therm_set); |
rostam | 0:b818a72ebb42 | 32 | disp.locate(0,10); |
rostam | 0:b818a72ebb42 | 33 | disp.printf("Room Temperature: %.2fc", room_temp); |
rostam | 0:b818a72ebb42 | 34 | |
rostam | 0:b818a72ebb42 | 35 | if (room_temp>24.0f) |
rostam | 0:b818a72ebb42 | 36 | { |
rostam | 0:b818a72ebb42 | 37 | toocold=0; |
rostam | 0:b818a72ebb42 | 38 | toohot=1; |
rostam | 0:b818a72ebb42 | 39 | } |
rostam | 0:b818a72ebb42 | 40 | else |
rostam | 0:b818a72ebb42 | 41 | { |
rostam | 0:b818a72ebb42 | 42 | toocold=1; |
rostam | 0:b818a72ebb42 | 43 | toohot=0; |
rostam | 0:b818a72ebb42 | 44 | } |
rostam | 0:b818a72ebb42 | 45 | |
rostam | 0:b818a72ebb42 | 46 | if(room_temp<therm_set) |
rostam | 0:b818a72ebb42 | 47 | heater=1; |
rostam | 0:b818a72ebb42 | 48 | else |
rostam | 0:b818a72ebb42 | 49 | heater=0; |
rostam | 0:b818a72ebb42 | 50 | |
rostam | 0:b818a72ebb42 | 51 | wait(0.1); |
rostam | 0:b818a72ebb42 | 52 | } |
rostam | 0:b818a72ebb42 | 53 | } |