
Temperature
Fork of IR_temperature by
main.cpp@1:acf9d29475a6, 2015-06-03 (annotated)
- Committer:
- TheScouser
- Date:
- Wed Jun 03 13:36:47 2015 +0000
- Revision:
- 1:acf9d29475a6
- Parent:
- 0:bbaf949d2a27
IR thermometer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:bbaf949d2a27 | 1 | #include "mbed.h" |
4180_1 | 0:bbaf949d2a27 | 2 | #include "mlx90614.h" |
4180_1 | 0:bbaf949d2a27 | 3 | |
TheScouser | 1:acf9d29475a6 | 4 | DigitalOut myled(LED1),p31(P0_29),p32(P0_30),laser_mod(p21); //displays I2C wait |
TheScouser | 1:acf9d29475a6 | 5 | DigitalIn tog_temp(p19),tog_gyro(p20); |
TheScouser | 1:acf9d29475a6 | 6 | I2C i2c(p9,p10); //sda,scl |
4180_1 | 0:bbaf949d2a27 | 7 | Serial pc(USBTX,USBRX); //serial usb config |
TheScouser | 1:acf9d29475a6 | 8 | |
4180_1 | 0:bbaf949d2a27 | 9 | MLX90614 IR_thermometer(&i2c); |
4180_1 | 0:bbaf949d2a27 | 10 | //setup an MLX90614 using MLX90614 library from |
4180_1 | 0:bbaf949d2a27 | 11 | // http://mbed.org/users/aquahika/libraries/MLX90614/lsixz6 |
TheScouser | 1:acf9d29475a6 | 12 | |
4180_1 | 0:bbaf949d2a27 | 13 | float temp; //temperature in degrees C |
TheScouser | 1:acf9d29475a6 | 14 | |
4180_1 | 0:bbaf949d2a27 | 15 | int main() { |
TheScouser | 1:acf9d29475a6 | 16 | p31 = 0; |
TheScouser | 1:acf9d29475a6 | 17 | p32 = 1; |
4180_1 | 0:bbaf949d2a27 | 18 | while (1) { |
TheScouser | 1:acf9d29475a6 | 19 | if(tog_temp){ |
TheScouser | 1:acf9d29475a6 | 20 | p31 = 0; |
TheScouser | 1:acf9d29475a6 | 21 | p32 = 1; |
TheScouser | 1:acf9d29475a6 | 22 | } |
TheScouser | 1:acf9d29475a6 | 23 | else if(tog_gyro){ |
TheScouser | 1:acf9d29475a6 | 24 | p31 = 1; |
TheScouser | 1:acf9d29475a6 | 25 | p32 = 0; |
TheScouser | 1:acf9d29475a6 | 26 | } |
TheScouser | 1:acf9d29475a6 | 27 | |
4180_1 | 0:bbaf949d2a27 | 28 | myled=1; // if led1 on - waiting on I2C |
TheScouser | 1:acf9d29475a6 | 29 | if(p32 == 1){ |
TheScouser | 1:acf9d29475a6 | 30 | |
TheScouser | 1:acf9d29475a6 | 31 | if (IR_thermometer.getTemp(&temp)) { |
TheScouser | 1:acf9d29475a6 | 32 | //gets temperature from sensor via I2C bus |
TheScouser | 1:acf9d29475a6 | 33 | myled=0; |
TheScouser | 1:acf9d29475a6 | 34 | //print temperature on PC |
TheScouser | 1:acf9d29475a6 | 35 | printf("Temperature is %5.1F degrees C\r\n",temp); |
TheScouser | 1:acf9d29475a6 | 36 | } |
TheScouser | 1:acf9d29475a6 | 37 | }else{ |
TheScouser | 1:acf9d29475a6 | 38 | printf("Gyro"); |
4180_1 | 0:bbaf949d2a27 | 39 | } |
4180_1 | 0:bbaf949d2a27 | 40 | //wait for device to produce next temperature reading |
4180_1 | 0:bbaf949d2a27 | 41 | wait(0.5); |
4180_1 | 0:bbaf949d2a27 | 42 | } |
TheScouser | 1:acf9d29475a6 | 43 | } |