Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BME280 SI1145
main.cpp@1:423c669d0306, 2017-06-27 (annotated)
- Committer:
- jonathanyost
- Date:
- Tue Jun 27 23:01:23 2017 +0000
- Revision:
- 1:423c669d0306
- Parent:
- 0:4354437a1033
- Child:
- 2:2bdf15b94f18
yeet;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jonathanyost | 0:4354437a1033 | 1 | #include "mbed.h" |
| jonathanyost | 0:4354437a1033 | 2 | #include <string> |
| jonathanyost | 0:4354437a1033 | 3 | |
| jonathanyost | 0:4354437a1033 | 4 | #define node_id (0x01) |
| jonathanyost | 0:4354437a1033 | 5 | #define tx (PA_9) |
| jonathanyost | 0:4354437a1033 | 6 | #define rx (PA_10) |
| jonathanyost | 0:4354437a1033 | 7 | |
| jonathanyost | 1:423c669d0306 | 8 | const int nodeID = 1; |
| jonathanyost | 1:423c669d0306 | 9 | |
| jonathanyost | 0:4354437a1033 | 10 | Serial xb(tx, rx); |
| jonathanyost | 0:4354437a1033 | 11 | Serial pc(D1, D0); |
| jonathanyost | 0:4354437a1033 | 12 | |
| jonathanyost | 1:423c669d0306 | 13 | //send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise); |
| jonathanyost | 1:423c669d0306 | 14 | //"id:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8" |
| jonathanyost | 1:423c669d0306 | 15 | void send_sensor_data(int t, int p, int h, int m, int u, int ir, int v, int n){ |
| jonathanyost | 1:423c669d0306 | 16 | //" id:2, te:%2,pr:%3,mo:%4,uv:%5,ir:%6,vi:%7,no:%8" |
| jonathanyost | 1:423c669d0306 | 17 | xb.printf("id:%d,te:%d,pr:%d,hu:%d,mo:%d,uv:%d,ir:%d,vi:%d,no:%d",nodeID,t,p,h,m,u,ir,v,n); |
| jonathanyost | 1:423c669d0306 | 18 | } |
| jonathanyost | 0:4354437a1033 | 19 | |
| jonathanyost | 1:423c669d0306 | 20 | void send_pir_data(int pir){ |
| jonathanyost | 1:423c669d0306 | 21 | xb.printf("PIR:%d",pir); |
| jonathanyost | 0:4354437a1033 | 22 | } |
| jonathanyost | 1:423c669d0306 | 23 | |
| jonathanyost | 0:4354437a1033 | 24 | int main() { |
| jonathanyost | 1:423c669d0306 | 25 | pc.printf("echo!!\n\r"); |
| jonathanyost | 0:4354437a1033 | 26 | // initialize read data chars |
| jonathanyost | 0:4354437a1033 | 27 | char pc_data = 'e'; |
| jonathanyost | 1:423c669d0306 | 28 | char buffer[128]; |
| jonathanyost | 0:4354437a1033 | 29 | |
| jonathanyost | 1:423c669d0306 | 30 | /* Sensor Data |
| jonathanyost | 1:423c669d0306 | 31 | format: "id:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8" |
| jonathanyost | 1:423c669d0306 | 32 | |
| jonathanyost | 1:423c669d0306 | 33 | |
| jonathanyost | 1:423c669d0306 | 34 | */ |
| jonathanyost | 0:4354437a1033 | 35 | |
| jonathanyost | 1:423c669d0306 | 36 | int temp = 0; |
| jonathanyost | 1:423c669d0306 | 37 | int pressure = 0; |
| jonathanyost | 1:423c669d0306 | 38 | int humidity = 0; |
| jonathanyost | 1:423c669d0306 | 39 | int motion = 0; |
| jonathanyost | 1:423c669d0306 | 40 | int uv = 0; |
| jonathanyost | 1:423c669d0306 | 41 | int ir = 0; |
| jonathanyost | 1:423c669d0306 | 42 | int vis = 0; |
| jonathanyost | 1:423c669d0306 | 43 | int noise = 0; |
| jonathanyost | 1:423c669d0306 | 44 | |
| jonathanyost | 0:4354437a1033 | 45 | while(true){ |
| jonathanyost | 0:4354437a1033 | 46 | if(pc.readable()){ |
| jonathanyost | 0:4354437a1033 | 47 | pc_data = pc.getc(); |
| jonathanyost | 0:4354437a1033 | 48 | pc.printf("%c", pc_data); |
| jonathanyost | 0:4354437a1033 | 49 | xb.printf("%c", pc_data); |
| jonathanyost | 0:4354437a1033 | 50 | } |
| jonathanyost | 0:4354437a1033 | 51 | |
| jonathanyost | 0:4354437a1033 | 52 | if(xb.readable()){ |
| jonathanyost | 0:4354437a1033 | 53 | xb.gets(buffer, 4); |
| jonathanyost | 1:423c669d0306 | 54 | pc.printf("%s", buffer); |
| jonathanyost | 1:423c669d0306 | 55 | } |
| jonathanyost | 1:423c669d0306 | 56 | |
| jonathanyost | 1:423c669d0306 | 57 | if(xb.writeable()){ |
| jonathanyost | 1:423c669d0306 | 58 | send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise); |
| jonathanyost | 0:4354437a1033 | 59 | } |
| jonathanyost | 0:4354437a1033 | 60 | } |
| jonathanyost | 0:4354437a1033 | 61 | } |
| jonathanyost | 0:4354437a1033 | 62 |