hadif azli
/
TEST123
BLYNK TEST
main.cpp@3:4cd9171ba989, 2016-06-16 (annotated)
- Committer:
- lixianyu
- Date:
- Thu Jun 16 08:08:30 2016 +0000
- Revision:
- 3:4cd9171ba989
- Parent:
- 2:6cd3b0947188
- Child:
- 5:8a3cf73d7ed3
9600?????ESP8266????????115200??ESP8266?????????9600????????????Timer???????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:d8f4c441e032 | 1 | #include "mbed.h" |
lixianyu | 1:0e75de2a5d21 | 2 | |
lixianyu | 3:4cd9171ba989 | 3 | #include "Config.h" |
lixianyu | 2:6cd3b0947188 | 4 | #include "MicroduinoPinNames.h" |
lixianyu | 2:6cd3b0947188 | 5 | DigitalOut myled(P0_20); |
lixianyu | 2:6cd3b0947188 | 6 | I2C g_i2c(P0_11, P0_10);//SDA, SCL |
lixianyu | 2:6cd3b0947188 | 7 | #include "SimpleTimer.h" |
lixianyu | 0:d8f4c441e032 | 8 | #include "userDef.h" |
lixianyu | 0:d8f4c441e032 | 9 | #include "sensor.h" |
lixianyu | 3:4cd9171ba989 | 10 | #ifdef OPEN_OLED |
lixianyu | 0:d8f4c441e032 | 11 | #include "oled.h" |
lixianyu | 2:6cd3b0947188 | 12 | #endif |
lixianyu | 3:4cd9171ba989 | 13 | #include "WiFiBlynk.h" |
lixianyu | 2:6cd3b0947188 | 14 | |
lixianyu | 3:4cd9171ba989 | 15 | Serial pc(P0_4, P0_0); // tx, rx |
lixianyu | 2:6cd3b0947188 | 16 | Timer g_Timer; |
lixianyu | 3:4cd9171ba989 | 17 | Ticker g_Ticker; |
lixianyu | 0:d8f4c441e032 | 18 | |
lixianyu | 2:6cd3b0947188 | 19 | void led_flash() |
lixianyu | 2:6cd3b0947188 | 20 | { |
lixianyu | 2:6cd3b0947188 | 21 | static int count = 0; |
lixianyu | 2:6cd3b0947188 | 22 | count++; |
lixianyu | 2:6cd3b0947188 | 23 | //pc.printf("count : %d, ms : %d\r\n", count, g_Timer.read_ms()); |
lixianyu | 3:4cd9171ba989 | 24 | myled = 1; |
lixianyu | 2:6cd3b0947188 | 25 | wait_ms(70); |
lixianyu | 2:6cd3b0947188 | 26 | myled = 0; |
lixianyu | 2:6cd3b0947188 | 27 | } |
lixianyu | 2:6cd3b0947188 | 28 | |
lixianyu | 3:4cd9171ba989 | 29 | static void led_flash_fast() |
lixianyu | 3:4cd9171ba989 | 30 | { |
lixianyu | 3:4cd9171ba989 | 31 | myled = !myled; |
lixianyu | 3:4cd9171ba989 | 32 | } |
lixianyu | 3:4cd9171ba989 | 33 | |
lixianyu | 3:4cd9171ba989 | 34 | #ifdef OPEN_OLED |
lixianyu | 2:6cd3b0947188 | 35 | Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128); |
lixianyu | 2:6cd3b0947188 | 36 | void update_oled() |
lixianyu | 2:6cd3b0947188 | 37 | { |
lixianyu | 2:6cd3b0947188 | 38 | myled = 1; |
lixianyu | 2:6cd3b0947188 | 39 | wait_ms(70); |
lixianyu | 2:6cd3b0947188 | 40 | myled = 0; |
lixianyu | 2:6cd3b0947188 | 41 | oled(adaf, sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh); |
lixianyu | 2:6cd3b0947188 | 42 | } |
lixianyu | 3:4cd9171ba989 | 43 | #endif |
lixianyu | 2:6cd3b0947188 | 44 | |
lixianyu | 0:d8f4c441e032 | 45 | int main() |
lixianyu | 0:d8f4c441e032 | 46 | { |
lixianyu | 3:4cd9171ba989 | 47 | g_Ticker.attach_us(led_flash_fast, 30000); |
lixianyu | 3:4cd9171ba989 | 48 | pc.baud(115200); |
lixianyu | 3:4cd9171ba989 | 49 | pc.printf("Enter main()\r\n"); |
lixianyu | 2:6cd3b0947188 | 50 | //myled = 1; |
lixianyu | 0:d8f4c441e032 | 51 | g_Timer.start(); |
lixianyu | 2:6cd3b0947188 | 52 | SimpleTimer gSimpleTimer(g_Timer); |
lixianyu | 3:4cd9171ba989 | 53 | |
lixianyu | 3:4cd9171ba989 | 54 | /* |
lixianyu | 3:4cd9171ba989 | 55 | * Set ESP8266 baud rate |
lixianyu | 3:4cd9171ba989 | 56 | * 在LPC824上,波特率设为115200时,ESP8266是无法工作 |
lixianyu | 3:4cd9171ba989 | 57 | */ |
lixianyu | 3:4cd9171ba989 | 58 | EspSerial.baud(9600); |
lixianyu | 0:d8f4c441e032 | 59 | |
lixianyu | 3:4cd9171ba989 | 60 | Blynk.begin(auth, wifi, SSID, PASS); |
lixianyu | 3:4cd9171ba989 | 61 | wait(5.0); |
lixianyu | 3:4cd9171ba989 | 62 | g_Ticker.detach(); |
lixianyu | 3:4cd9171ba989 | 63 | |
lixianyu | 0:d8f4c441e032 | 64 | // Setup a function to be called every second |
lixianyu | 3:4cd9171ba989 | 65 | gSimpleTimer.setInterval(2000L, senTempHumi); |
lixianyu | 2:6cd3b0947188 | 66 | gSimpleTimer.setInterval(1000, updateLight); |
lixianyu | 2:6cd3b0947188 | 67 | gSimpleTimer.setInterval(5000, updateCH4); |
lixianyu | 2:6cd3b0947188 | 68 | gSimpleTimer.setInterval(4000, updateTempHumi); |
lixianyu | 2:6cd3b0947188 | 69 | //gSimpleTimer.setInterval(3000, PM25); |
lixianyu | 3:4cd9171ba989 | 70 | gSimpleTimer.setInterval(4000, led_flash); |
lixianyu | 3:4cd9171ba989 | 71 | #ifdef OPEN_OLED |
lixianyu | 2:6cd3b0947188 | 72 | gSimpleTimer.setInterval(1000, update_oled); |
lixianyu | 3:4cd9171ba989 | 73 | #endif |
lixianyu | 2:6cd3b0947188 | 74 | //PM25_init(); |
lixianyu | 1:0e75de2a5d21 | 75 | wait_ms(2000); |
lixianyu | 3:4cd9171ba989 | 76 | #ifdef OPEN_OLED |
lixianyu | 2:6cd3b0947188 | 77 | oled_init(adaf); |
lixianyu | 3:4cd9171ba989 | 78 | #endif |
lixianyu | 2:6cd3b0947188 | 79 | int pretime = g_Timer.read_ms(); |
lixianyu | 0:d8f4c441e032 | 80 | while(1) { |
lixianyu | 2:6cd3b0947188 | 81 | //pc.printf("Enter while(1)\r\n"); |
lixianyu | 2:6cd3b0947188 | 82 | //myled = !myled; |
lixianyu | 3:4cd9171ba989 | 83 | Blynk.run(); // All the Blynk Magic happens here... |
lixianyu | 2:6cd3b0947188 | 84 | gSimpleTimer.run(); |
lixianyu | 3:4cd9171ba989 | 85 | #if 0 |
lixianyu | 2:6cd3b0947188 | 86 | int curtime = g_Timer.read_ms(); |
lixianyu | 2:6cd3b0947188 | 87 | if (curtime - pretime > 4000) { |
lixianyu | 2:6cd3b0947188 | 88 | //updateTempHumi(); |
lixianyu | 2:6cd3b0947188 | 89 | led_flash(); |
lixianyu | 2:6cd3b0947188 | 90 | pretime = curtime; |
lixianyu | 0:d8f4c441e032 | 91 | } |
lixianyu | 3:4cd9171ba989 | 92 | #endif |
lixianyu | 3:4cd9171ba989 | 93 | |
lixianyu | 0:d8f4c441e032 | 94 | } |
lixianyu | 0:d8f4c441e032 | 95 | } |