92
Dependencies: ADXL362 ATParser MPL3115A2 TSL2561 mbed
Fork of Lab91 by
main.cpp
- Committer:
- fanbsun
- Date:
- 2018-04-20
- Revision:
- 6:074cf15af4a2
- Parent:
- 5:4a5b8c114486
- Child:
- 7:0f8f06ef71dd
- Child:
- 8:a3f81e46a122
File content as of revision 6:074cf15af4a2:
#include "mbed.h" #include "MPL3115A2.h" #include <string> #include <math.h> #include <ATParser.h> #include "BufferedSerial.h" #include "TSL2561.h" //Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut myled(LED1); DigitalOut powerpin(PA_8); // GPIO pin //BufferedSerial pc(SERIAL_TX, SERIAL_RX); BufferedSerial device(PA_9, PA_10); // Selects SDA as I2C1_SDA on pin PB_7 // Selects SCL on I2C1_SCL on pin PB_6 // The I2C address of the pressure sensor is fixed at 0x60. MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); TSL2561 lightsensor(PB_4,PA_7); int main() { uint8_t id; double p, t, l; myled = 0; powerpin = 0; ATParser at = ATParser(device, "\r\n", 256, 2000, false); char buffer[30]; char buffer1[30]; // pc.baud(115200); device.baud(115200); // pc.printf("Hello"); at.send("AT+NI=1,MTCDT-19400691\n\r") && at.recv("OK"); at.send("AT+NK=1,MTCDT-19400691\n\r") && at.recv("OK"); at.send("AT+FSB=1\n\r") && at.recv("OK"); at.send("AT+JOIN\n\r") && at.recv("OK"); while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect { wait(1); } while(1) { l=lightsensor.lux(); p=pressure_sensor.getPressure(); t=pressure_sensor.getTemperature(); sprintf(buffer1, "AT+SEND=%.4f\n\r", l); sprintf(buffer, "AT+SEND=%.1f,%.1f\n\r", p, t); buffer[20] = '\0'; // pc.printf(buffer); at.send(buffer) && at.recv("OK"); at.send(buffer1) && at.recv("OK"); wait(10); } }