Junichi Katsu
/
MilkcocoaOsSample_Eth_sensor
mbed(エンベッド)の仕組みを学び、試作体験!用のサンプル
Fork of MilkcocoaOsSample_Eth by
Diff: main.cpp
- Revision:
- 8:d5c4aa73f69e
- Parent:
- 7:49a5a7e621d6
diff -r 49a5a7e621d6 -r d5c4aa73f69e main.cpp --- a/main.cpp Sun Aug 06 15:49:14 2017 +0000 +++ b/main.cpp Mon Aug 07 02:41:17 2017 +0000 @@ -5,6 +5,9 @@ EthernetInterface eth; RawSerial pc(USBTX,USBRX); AnalogIn sensor(A1); +InterruptIn motion(D2); + +int motion_detected = 0; /************************* Your Milkcocoa Setup *********************************/ @@ -21,9 +24,15 @@ extern void onpush(MQTT::MessageData& md); +void irq_handler(void) +{ + motion_detected = 1; +} int main() { float val; + int motion_cnt = 0; + pc.baud(9600); pc.printf("Milkcocoa mbed os ver demo\n\r\n\r\n\r"); @@ -37,12 +46,23 @@ Milkcocoa* milkcocoa = new Milkcocoa(ð, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID); milkcocoa->connect(); + + motion.rise(&irq_handler); while(1) { DataElement elem = DataElement(); val = sensor.read(); - pc.printf("light = %f\r\n",val); + + if(motion_detected == 1) { + motion_cnt++; + motion_detected = 0; + } + elem.setValue("light", val); + elem.setValue("motion", motion_cnt); + + + pc.printf("light = %f motion = %d\r\n",val,motion_cnt); milkcocoa->push(MILKCOCOA_DATASTORE, elem);