Second coding part of lab 9
Dependencies: ADXL362 Lab7 mbed
main.cpp@0:63f971f6c872, 2018-04-11 (annotated)
- Committer:
- dprowe
- Date:
- Wed Apr 11 01:34:07 2018 +0000
- Revision:
- 0:63f971f6c872
the second coding part
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dprowe | 0:63f971f6c872 | 1 | #include "mbed.h" |
dprowe | 0:63f971f6c872 | 2 | #include "ADXL362.h" |
dprowe | 0:63f971f6c872 | 3 | #include "MPL3115A2.h" |
dprowe | 0:63f971f6c872 | 4 | #include <stdio.h> |
dprowe | 0:63f971f6c872 | 5 | #include <stdlib.h> |
dprowe | 0:63f971f6c872 | 6 | |
dprowe | 0:63f971f6c872 | 7 | |
dprowe | 0:63f971f6c872 | 8 | DigitalOut myled(LED1); |
dprowe | 0:63f971f6c872 | 9 | ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1); |
dprowe | 0:63f971f6c872 | 10 | MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); |
dprowe | 0:63f971f6c872 | 11 | InterruptIn event(PA_4); |
dprowe | 0:63f971f6c872 | 12 | |
dprowe | 0:63f971f6c872 | 13 | Serial pc(SERIAL_TX, SERIAL_RX, 115200); |
dprowe | 0:63f971f6c872 | 14 | Serial device(PA_9, PA_10, 115200); |
dprowe | 0:63f971f6c872 | 15 | |
dprowe | 0:63f971f6c872 | 16 | |
dprowe | 0:63f971f6c872 | 17 | void blink() { |
dprowe | 0:63f971f6c872 | 18 | myled = 1; // LED is ON |
dprowe | 0:63f971f6c872 | 19 | wait(1); // 1 sec |
dprowe | 0:63f971f6c872 | 20 | myled = 0; // LED is OFF |
dprowe | 0:63f971f6c872 | 21 | wait(1); |
dprowe | 0:63f971f6c872 | 22 | |
dprowe | 0:63f971f6c872 | 23 | } |
dprowe | 0:63f971f6c872 | 24 | |
dprowe | 0:63f971f6c872 | 25 | int main() { |
dprowe | 0:63f971f6c872 | 26 | device.printf("AT+FSB=1\n"); |
dprowe | 0:63f971f6c872 | 27 | wait(1); |
dprowe | 0:63f971f6c872 | 28 | device.printf("AT+NI=1,MTCDT-19400691\n"); |
dprowe | 0:63f971f6c872 | 29 | wait(1); |
dprowe | 0:63f971f6c872 | 30 | device.printf("AT+NK=1,MTCDT-19400691\n"); |
dprowe | 0:63f971f6c872 | 31 | wait(1); |
dprowe | 0:63f971f6c872 | 32 | device.printf("AT+JOIN\n"); |
dprowe | 0:63f971f6c872 | 33 | wait(1); |
dprowe | 0:63f971f6c872 | 34 | |
dprowe | 0:63f971f6c872 | 35 | int i = 0; |
dprowe | 0:63f971f6c872 | 36 | while(i<3){ |
dprowe | 0:63f971f6c872 | 37 | blink(); |
dprowe | 0:63f971f6c872 | 38 | i++; |
dprowe | 0:63f971f6c872 | 39 | } |
dprowe | 0:63f971f6c872 | 40 | |
dprowe | 0:63f971f6c872 | 41 | |
dprowe | 0:63f971f6c872 | 42 | double altitudeReading; |
dprowe | 0:63f971f6c872 | 43 | double tempReading; |
dprowe | 0:63f971f6c872 | 44 | altitudeReading = pressure_sensor.getAltitude(); |
dprowe | 0:63f971f6c872 | 45 | tempReading = pressure_sensor.getTemperature(); |
dprowe | 0:63f971f6c872 | 46 | device.printf("AT+SEND=%.2f %.1f\n",tempReading,altitudeReading); |
dprowe | 0:63f971f6c872 | 47 | |
dprowe | 0:63f971f6c872 | 48 | while(1) { |
dprowe | 0:63f971f6c872 | 49 | wait(3600); |
dprowe | 0:63f971f6c872 | 50 | double altitudeReading; |
dprowe | 0:63f971f6c872 | 51 | double tempReading; |
dprowe | 0:63f971f6c872 | 52 | altitudeReading = pressure_sensor.getAltitude(); |
dprowe | 0:63f971f6c872 | 53 | tempReading = pressure_sensor.getTemperature(); |
dprowe | 0:63f971f6c872 | 54 | device.printf("AT+SEND=%.2f %.1f\n",tempReading,altitudeReading); |
dprowe | 0:63f971f6c872 | 55 | } |
dprowe | 0:63f971f6c872 | 56 | } |