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@0:b818a72ebb42, 2013-12-29 (annotated)
- Committer:
- rostam
- Date:
- Sun Dec 29 16:42:37 2013 +0000
- Revision:
- 0:b818a72ebb42
- Child:
- 1:4a768c18e543
Initial issue of the programme. The programme uses the LM75B sensor to measure the room temperature and switches appropriate LEDs on when too hot or too cold. It uses Pot 1 analogue input of the NXP LPC1768 Microcontroller mbed application board to si...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rostam | 0:b818a72ebb42 | 1 | #include "mbed.h" |
rostam | 0:b818a72ebb42 | 2 | #include "C12832_lcd.h" |
rostam | 0:b818a72ebb42 | 3 | #include "LM75B.h" |
rostam | 0:b818a72ebb42 | 4 | |
rostam | 0:b818a72ebb42 | 5 | DigitalOut toohot(LED1); |
rostam | 0:b818a72ebb42 | 6 | DigitalOut toocold(LED2); |
rostam | 0:b818a72ebb42 | 7 | DigitalOut heater(LED4); |
rostam | 0:b818a72ebb42 | 8 | |
rostam | 0:b818a72ebb42 | 9 | C12832_LCD disp; |
rostam | 0:b818a72ebb42 | 10 | LM75B temp(p28,p27); |
rostam | 0:b818a72ebb42 | 11 | AnalogIn therm(p19); |
rostam | 0:b818a72ebb42 | 12 | |
rostam | 0:b818a72ebb42 | 13 | float room_temp; |
rostam | 0:b818a72ebb42 | 14 | float therm_set; |
rostam | 0:b818a72ebb42 | 15 | |
rostam | 0:b818a72ebb42 | 16 | int main() |
rostam | 0:b818a72ebb42 | 17 | { |
rostam | 0:b818a72ebb42 | 18 | toocold=0; |
rostam | 0:b818a72ebb42 | 19 | toohot=0; |
rostam | 0:b818a72ebb42 | 20 | |
rostam | 0:b818a72ebb42 | 21 | while(1) |
rostam | 0:b818a72ebb42 | 22 | { |
rostam | 0:b818a72ebb42 | 23 | |
rostam | 0:b818a72ebb42 | 24 | therm_set=therm.read() *45.0f; |
rostam | 0:b818a72ebb42 | 25 | room_temp=temp.read(); |
rostam | 0:b818a72ebb42 | 26 | disp.cls(); |
rostam | 0:b818a72ebb42 | 27 | disp.locate(0,0); |
rostam | 0:b818a72ebb42 | 28 | disp.printf("Thermostat setting: %.2fc", therm_set); |
rostam | 0:b818a72ebb42 | 29 | disp.locate(0,10); |
rostam | 0:b818a72ebb42 | 30 | disp.printf("Room Temperature: %.2fc", room_temp); |
rostam | 0:b818a72ebb42 | 31 | |
rostam | 0:b818a72ebb42 | 32 | if (room_temp>24.0f) |
rostam | 0:b818a72ebb42 | 33 | { |
rostam | 0:b818a72ebb42 | 34 | toocold=0; |
rostam | 0:b818a72ebb42 | 35 | toohot=1; |
rostam | 0:b818a72ebb42 | 36 | } |
rostam | 0:b818a72ebb42 | 37 | else |
rostam | 0:b818a72ebb42 | 38 | { |
rostam | 0:b818a72ebb42 | 39 | toocold=1; |
rostam | 0:b818a72ebb42 | 40 | toohot=0; |
rostam | 0:b818a72ebb42 | 41 | } |
rostam | 0:b818a72ebb42 | 42 | |
rostam | 0:b818a72ebb42 | 43 | if(room_temp<therm_set) |
rostam | 0:b818a72ebb42 | 44 | heater=1; |
rostam | 0:b818a72ebb42 | 45 | else |
rostam | 0:b818a72ebb42 | 46 | heater=0; |
rostam | 0:b818a72ebb42 | 47 | |
rostam | 0:b818a72ebb42 | 48 | wait(0.1); |
rostam | 0:b818a72ebb42 | 49 | } |
rostam | 0:b818a72ebb42 | 50 | } |