Set upper and lower alarms and trhoug pin PB_13 monitor the ALERT signal, turn on/0ff a led when the temperature is below or above the alarm values.
Dependencies: Hotboards_temp mbed
main.cpp@0:8fcaf7cf5b69, 2016-03-22 (annotated)
- Committer:
- Hotboards
- Date:
- Tue Mar 22 21:58:17 2016 +0000
- Revision:
- 0:8fcaf7cf5b69
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hotboards | 0:8fcaf7cf5b69 | 1 | /* |
Hotboards | 0:8fcaf7cf5b69 | 2 | Hotboards temp Library - setting alarms |
Hotboards | 0:8fcaf7cf5b69 | 3 | Set upper and lower alarms and trhoug pin PB_13 monitor the ALERT signal, turn on a led when the |
Hotboards | 0:8fcaf7cf5b69 | 4 | temperature is below or above the alarm values. |
Hotboards | 0:8fcaf7cf5b69 | 5 | The circuit |
Hotboards | 0:8fcaf7cf5b69 | 6 | * VDD --> 3.3v |
Hotboards | 0:8fcaf7cf5b69 | 7 | * SDA --> PB_9 |
Hotboards | 0:8fcaf7cf5b69 | 8 | * SCL --> PB_8 |
Hotboards | 0:8fcaf7cf5b69 | 9 | * ALERT --> PB_13 |
Hotboards | 0:8fcaf7cf5b69 | 10 | * GND --> GND |
Hotboards | 0:8fcaf7cf5b69 | 11 | Library and example created by Diego from Hotboards |
Hotboards | 0:8fcaf7cf5b69 | 12 | Ported to mbed by Pedro from Hotboards |
Hotboards | 0:8fcaf7cf5b69 | 13 | This example code is in the public domain. |
Hotboards | 0:8fcaf7cf5b69 | 14 | */ |
Hotboards | 0:8fcaf7cf5b69 | 15 | #include "mbed.h" |
Hotboards | 0:8fcaf7cf5b69 | 16 | #include "Hotboards_temp.h" |
Hotboards | 0:8fcaf7cf5b69 | 17 | |
Hotboards | 0:8fcaf7cf5b69 | 18 | // input pin for reading the alert signal |
Hotboards | 0:8fcaf7cf5b69 | 19 | DigitalIn Alert(PB_13); |
Hotboards | 0:8fcaf7cf5b69 | 20 | // Onboard led |
Hotboards | 0:8fcaf7cf5b69 | 21 | DigitalOut myLed( LED1 ); |
Hotboards | 0:8fcaf7cf5b69 | 22 | //new serial port instance |
Hotboards | 0:8fcaf7cf5b69 | 23 | Serial pc(USBTX, USBRX); |
Hotboards | 0:8fcaf7cf5b69 | 24 | //I2C bus instance for the library |
Hotboards | 0:8fcaf7cf5b69 | 25 | I2C device( I2C_SDA, I2C_SCL ); |
Hotboards | 0:8fcaf7cf5b69 | 26 | // instance a sensor with address number 7 (none of the jumpers on the board is short circuited) |
Hotboards | 0:8fcaf7cf5b69 | 27 | // and also 0.5 celsius degrees resolution |
Hotboards | 0:8fcaf7cf5b69 | 28 | Hotboards_temp sensor( device, Sensor_7); |
Hotboards | 0:8fcaf7cf5b69 | 29 | |
Hotboards | 0:8fcaf7cf5b69 | 30 | |
Hotboards | 0:8fcaf7cf5b69 | 31 | |
Hotboards | 0:8fcaf7cf5b69 | 32 | int main( void ) |
Hotboards | 0:8fcaf7cf5b69 | 33 | { |
Hotboards | 0:8fcaf7cf5b69 | 34 | |
Hotboards | 0:8fcaf7cf5b69 | 35 | // init sensor |
Hotboards | 0:8fcaf7cf5b69 | 36 | sensor.init(); |
Hotboards | 0:8fcaf7cf5b69 | 37 | // set lower alarm to 0.0 C and upper alarm to 26.0 C. We assume the eviromental temp is around |
Hotboards | 0:8fcaf7cf5b69 | 38 | // 23-32 degrees |
Hotboards | 0:8fcaf7cf5b69 | 39 | sensor.setAlarms( 0.0, 30.0 ); |
Hotboards | 0:8fcaf7cf5b69 | 40 | |
Hotboards | 0:8fcaf7cf5b69 | 41 | while(1) |
Hotboards | 0:8fcaf7cf5b69 | 42 | { |
Hotboards | 0:8fcaf7cf5b69 | 43 | // sense the ALERT signal and turn on/off the led on your Nucleo board |
Hotboards | 0:8fcaf7cf5b69 | 44 | if(Alert == 0) |
Hotboards | 0:8fcaf7cf5b69 | 45 | { |
Hotboards | 0:8fcaf7cf5b69 | 46 | myLed = 1; |
Hotboards | 0:8fcaf7cf5b69 | 47 | } |
Hotboards | 0:8fcaf7cf5b69 | 48 | else |
Hotboards | 0:8fcaf7cf5b69 | 49 | { |
Hotboards | 0:8fcaf7cf5b69 | 50 | myLed =0; |
Hotboards | 0:8fcaf7cf5b69 | 51 | } |
Hotboards | 0:8fcaf7cf5b69 | 52 | |
Hotboards | 0:8fcaf7cf5b69 | 53 | // read temperature in celcius degrees |
Hotboards | 0:8fcaf7cf5b69 | 54 | float temp = sensor.read(); |
Hotboards | 0:8fcaf7cf5b69 | 55 | // print it on the serial port |
Hotboards | 0:8fcaf7cf5b69 | 56 | pc.printf("Temp sensor 1: %3.1f C\r\n",temp); |
Hotboards | 0:8fcaf7cf5b69 | 57 | // take the next value after 2 sec (just to not read too often) |
Hotboards | 0:8fcaf7cf5b69 | 58 | wait(2); |
Hotboards | 0:8fcaf7cf5b69 | 59 | } |
Hotboards | 0:8fcaf7cf5b69 | 60 | } |