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.
Fork of MilkcocoaOsSample_Eth by
Revision 8:d5c4aa73f69e, committed 2017-08-07
- Comitter:
- jksoft
- Date:
- Mon Aug 07 02:41:17 2017 +0000
- Parent:
- 7:49a5a7e621d6
- Commit message:
- motion sensor add
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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);
