test

Dependencies:   mbed XBee

Revision:
2:cb2bd28bb66d
Parent:
1:cb2c4d733c1b
--- a/main.cpp	Fri Jan 15 08:50:35 2021 +0000
+++ b/main.cpp	Fri Apr 16 09:34:17 2021 +0000
@@ -1,21 +1,51 @@
 #include "mbed.h"
 #include "Controller.h"
 
-Controller Con(p28,p27,115200);
 Serial pc(USBTX,USBRX,115200);
+Ticker timer;
+DigitalOut myled2(LED2);
+
+XBee_APIMode Con(p28,p27);
 
-int main()
-{
-    Con.DRbegin();
-    while(1) {
-        double joyRX = Con.readJoyRXbyte();
-        double joyRY = Con.readJoyRYbyte();
-        double joyLX = Con.readJoyLXbyte();
-        double joyLY = Con.readJoyLYbyte();
-        unsigned int buttonstate = Con.getButtonState();
-        if(buttonstate & BUTTON_MARU) pc.printf("%d\n",Con.getButtonState());
-        else if(buttonstate & BUTTON_L2) pc.printf("%3.0lf %3.0lf %3.0lf %3.0lf\n",joyRX,joyRY,joyLX,joyLY);
-        else pc.printf("PUSH!\n");
-        //wait(0.01);
+bool flag_10ms = false;
+bool flag_1s = false;
+
+void warikomi(){
+    flag_10ms = true;
+    static int a = 0;
+    if(a++ > 100){
+        flag_1s = true;
+        a = 0;
     }
 }
+
+void setup()
+{   
+    wait(1);
+    myled2.write(0);
+    Con.begin(115200);
+    timer.attach(warikomi,0.01);
+}
+
+void loop()
+{
+    int serial_num = Con.update();
+    if(flag_10ms)
+    {
+        pc.printf("%d\t%d\n",serial_num,Con.getButtonState());
+        
+        flag_10ms = false;
+    }
+    if(flag_1s)
+    {
+        myled2.write(!myled2.read());
+        flag_1s = false;
+    }
+}
+    
+int main(void)
+{
+    setup();
+    for(;;)loop();
+    return 0;
+}