version2...

Dependencies:   mbed

Revision:
1:4a28329e243f
Parent:
0:10d259a3b185
Child:
2:238093c1d98d
Child:
3:d015f636e4e3
--- a/main.cpp	Thu Apr 16 09:44:38 2015 +0000
+++ b/main.cpp	Thu Apr 16 11:15:25 2015 +0000
@@ -1,9 +1,47 @@
 #include "mbed.h"
+#include "iostream"
+#include "stdio.h"
+#include "stdlib.h"
 
+using namespace std;
+
+Serial xbee1(PA_2, PA_3);
+//DigitalOut rst1(p11);
 DigitalOut myled(LED1);
+DigitalIn mybutton(USER_BUTTON);
 
-int main() {
+int counter = 0;
+void sendsignal();
+void receivesignal(char bericht);
+
+int main()
+{
     while(1) {
+        if(xbee1.readable()) {
+            int message = xbee1.getc(); //XBee read
+            receivesignal(message);
+        }
+        if (mybutton == 0) { //if button pressed
+            sendsignal();
+        }
+    }
+}
+
+void sendsignal()
+{
+    if(counter == 0) {
+        xbee1.putc(counter); //XBee write
+    }
+    if (counter == 1) {
+        xbee1.putc(counter);
+        counter = 0;
+    }
+}
+
+void receivesignal(int  bericht)
+{
+    if (bericht == 0) {
+        //make button signal x
         myled = 1; // LED is ON
         wait(0.1); // 200 ms
         myled = 0; // LED is OFF
@@ -13,4 +51,10 @@
         myled = 0;
         wait(0.4);
     }
-}
+    if (bericht == 1) {
+        myled = 1; // LED is ON
+        wait(1.0); // 200 ms
+        myled = 0; // LED is OFF
+        wait(1.0); // 1 sec
+    }
+}
\ No newline at end of file