updated
Dependencies: mbed Nucleo_Sensor_Shield
main.cpp@3:53d2d440a695, 2019-01-30 (annotated)
- Committer:
- selvakumararm
- Date:
- Wed Jan 30 03:03:58 2019 +0000
- Revision:
- 3:53d2d440a695
- Parent:
- 2:28f8cd15fca4
- Child:
- 4:0c2adcf321c4
IoT Exam Jan 2019
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kennethwfk | 0:fc777b6c55d6 | 1 | |
kennethwfk | 0:fc777b6c55d6 | 2 | |
kennethwfk | 0:fc777b6c55d6 | 3 | #include "mbed.h" |
kennethwfk | 0:fc777b6c55d6 | 4 | #include "x_cube_mems.h" |
kennethwfk | 0:fc777b6c55d6 | 5 | |
kennethwfk | 0:fc777b6c55d6 | 6 | DigitalOut led(LED1); |
kennethwfk | 0:fc777b6c55d6 | 7 | |
kennethwfk | 0:fc777b6c55d6 | 8 | Serial pc(USBTX, USBRX); |
kennethwfk | 0:fc777b6c55d6 | 9 | |
kennethwfk | 0:fc777b6c55d6 | 10 | Ticker blinky; |
kennethwfk | 0:fc777b6c55d6 | 11 | Ticker update; |
kennethwfk | 0:fc777b6c55d6 | 12 | |
kennethwfk | 0:fc777b6c55d6 | 13 | volatile float TEMPERATURE_C; |
selvakumararm | 3:53d2d440a695 | 14 | |
selvakumararm | 3:53d2d440a695 | 15 | <<<<<<<<Declarations should be here >>>>>>>>>> |
selvakumararm | 3:53d2d440a695 | 16 | |
kennethwfk | 0:fc777b6c55d6 | 17 | |
kennethwfk | 0:fc777b6c55d6 | 18 | bool measurements_update = false; |
kennethwfk | 0:fc777b6c55d6 | 19 | |
kennethwfk | 0:fc777b6c55d6 | 20 | void blinky_handler(){ |
kennethwfk | 0:fc777b6c55d6 | 21 | led = !led; |
kennethwfk | 0:fc777b6c55d6 | 22 | } |
kennethwfk | 0:fc777b6c55d6 | 23 | |
kennethwfk | 0:fc777b6c55d6 | 24 | void sensors_handler(){ |
kennethwfk | 0:fc777b6c55d6 | 25 | measurements_update = true; |
kennethwfk | 0:fc777b6c55d6 | 26 | } |
kennethwfk | 0:fc777b6c55d6 | 27 | |
kennethwfk | 0:fc777b6c55d6 | 28 | int main() { |
kennethwfk | 0:fc777b6c55d6 | 29 | |
selvakumararm | 2:28f8cd15fca4 | 30 | |
kennethwfk | 0:fc777b6c55d6 | 31 | static X_CUBE_MEMS *Sensors = X_CUBE_MEMS::Instance(); |
kennethwfk | 0:fc777b6c55d6 | 32 | |
selvakumararm | 2:28f8cd15fca4 | 33 | |
kennethwfk | 0:fc777b6c55d6 | 34 | blinky.attach(&blinky_handler, 0.5); |
kennethwfk | 0:fc777b6c55d6 | 35 | update.attach(&sensors_handler, 3); |
kennethwfk | 0:fc777b6c55d6 | 36 | |
kennethwfk | 0:fc777b6c55d6 | 37 | while(1) { |
kennethwfk | 0:fc777b6c55d6 | 38 | |
kennethwfk | 0:fc777b6c55d6 | 39 | if(measurements_update == true){ |
kennethwfk | 0:fc777b6c55d6 | 40 | /* Read the environmental sensors */ |
kennethwfk | 0:fc777b6c55d6 | 41 | |
selvakumararm | 3:53d2d440a695 | 42 | <<<<<<<< your code should be here >>>>>>>>>> |
selvakumararm | 2:28f8cd15fca4 | 43 | |
selvakumararm | 2:28f8cd15fca4 | 44 | |
kennethwfk | 0:fc777b6c55d6 | 45 | pc.printf("Temperature:\t %.2f C / %.2f F / %.2f K\r\n", TEMPERATURE_C, TEMPERATURE_F, TEMPERATURE_K); |
selvakumararm | 3:53d2d440a695 | 46 | |
selvakumararm | 2:28f8cd15fca4 | 47 | |
kennethwfk | 0:fc777b6c55d6 | 48 | |
kennethwfk | 0:fc777b6c55d6 | 49 | pc.printf("\r\n"); |
kennethwfk | 0:fc777b6c55d6 | 50 | |
kennethwfk | 0:fc777b6c55d6 | 51 | measurements_update = false; |
kennethwfk | 0:fc777b6c55d6 | 52 | } |
kennethwfk | 0:fc777b6c55d6 | 53 | __wfi(); |
kennethwfk | 0:fc777b6c55d6 | 54 | } |
kennethwfk | 0:fc777b6c55d6 | 55 | } |