TX for Temperature Controlled Fan
Dependencies: 4DGL-uLCD-SE MLX90614 mbed
main.cpp@0:8c4f29688d9d, 2016-04-29 (annotated)
- Committer:
- TimothyY
- Date:
- Fri Apr 29 01:08:48 2016 +0000
- Revision:
- 0:8c4f29688d9d
TxFinal
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TimothyY | 0:8c4f29688d9d | 1 | #include "mbed.h" |
TimothyY | 0:8c4f29688d9d | 2 | #include "mlx90614.h" |
TimothyY | 0:8c4f29688d9d | 3 | #include "uLCD_4DGL.h" |
TimothyY | 0:8c4f29688d9d | 4 | |
TimothyY | 0:8c4f29688d9d | 5 | I2C i2c(p28,p27); //sda,scl |
TimothyY | 0:8c4f29688d9d | 6 | |
TimothyY | 0:8c4f29688d9d | 7 | MLX90614 IR_thermometer(&i2c); |
TimothyY | 0:8c4f29688d9d | 8 | //setup an MLX90614 using MLX90614 library from |
TimothyY | 0:8c4f29688d9d | 9 | // http://mbed.org/users/aquahika/libraries/MLX90614/lsixz6 |
TimothyY | 0:8c4f29688d9d | 10 | |
TimothyY | 0:8c4f29688d9d | 11 | DigitalIn sw(p20); |
TimothyY | 0:8c4f29688d9d | 12 | |
TimothyY | 0:8c4f29688d9d | 13 | Serial pc(USBTX, USBRX); |
TimothyY | 0:8c4f29688d9d | 14 | |
TimothyY | 0:8c4f29688d9d | 15 | Serial xbee1(p9,p10); |
TimothyY | 0:8c4f29688d9d | 16 | |
TimothyY | 0:8c4f29688d9d | 17 | uLCD_4DGL uLCD(p13,p14,p11); |
TimothyY | 0:8c4f29688d9d | 18 | |
TimothyY | 0:8c4f29688d9d | 19 | DigitalOut myled(LED1); |
TimothyY | 0:8c4f29688d9d | 20 | DigitalOut myled3(LED3);//Create variable for Led 3 on the mbed |
TimothyY | 0:8c4f29688d9d | 21 | |
TimothyY | 0:8c4f29688d9d | 22 | int main() { |
TimothyY | 0:8c4f29688d9d | 23 | |
TimothyY | 0:8c4f29688d9d | 24 | sw.mode(PullUp); |
TimothyY | 0:8c4f29688d9d | 25 | |
TimothyY | 0:8c4f29688d9d | 26 | float current_temp = 0.0; |
TimothyY | 0:8c4f29688d9d | 27 | |
TimothyY | 0:8c4f29688d9d | 28 | wait(5.0); |
TimothyY | 0:8c4f29688d9d | 29 | uLCD.printf("Your temp is:"); |
TimothyY | 0:8c4f29688d9d | 30 | while (1) { |
TimothyY | 0:8c4f29688d9d | 31 | wait(1.0); |
TimothyY | 0:8c4f29688d9d | 32 | myled=1; // if led1 on - waiting on I2C |
TimothyY | 0:8c4f29688d9d | 33 | if (IR_thermometer.getTemp(¤t_temp)) { |
TimothyY | 0:8c4f29688d9d | 34 | //gets temperature from sensor via I2C bus |
TimothyY | 0:8c4f29688d9d | 35 | |
TimothyY | 0:8c4f29688d9d | 36 | if (sw == 1) { |
TimothyY | 0:8c4f29688d9d | 37 | xbee1.printf("%d \n\r", (int) current_temp); |
TimothyY | 0:8c4f29688d9d | 38 | } |
TimothyY | 0:8c4f29688d9d | 39 | //pc.printf("data %d \n\r", (int) current_temp); |
TimothyY | 0:8c4f29688d9d | 40 | myled=0; |
TimothyY | 0:8c4f29688d9d | 41 | uLCD.text_height(3); |
TimothyY | 0:8c4f29688d9d | 42 | uLCD.text_width(3); |
TimothyY | 0:8c4f29688d9d | 43 | uLCD.locate(1,2); |
TimothyY | 0:8c4f29688d9d | 44 | uLCD.printf("%d C", (int) current_temp); |
TimothyY | 0:8c4f29688d9d | 45 | wait(0.3); |
TimothyY | 0:8c4f29688d9d | 46 | myled3=1; |
TimothyY | 0:8c4f29688d9d | 47 | wait(1.0); |
TimothyY | 0:8c4f29688d9d | 48 | //wait for device to produce next temperature reading |
TimothyY | 0:8c4f29688d9d | 49 | } |
TimothyY | 0:8c4f29688d9d | 50 | } |
TimothyY | 0:8c4f29688d9d | 51 | } |