New group

Dependencies:   mbed

Fork of TAIST_modbus by Supachai Vorapojpisut

Revision:
6:5bb5238f2f6e
Parent:
5:843e67c675c1
Child:
7:774c2b305d2d
--- a/main.cpp	Wed Mar 14 08:03:00 2018 +0000
+++ b/main.cpp	Wed Mar 14 08:30:53 2018 +0000
@@ -5,9 +5,9 @@
 InterruptIn button(USER_BUTTON);
 RawSerial pc(USBTX, USBRX);
 
-float cunt_pressed = 0.0;
-float cunt_released = 0.0;
-float x,y;
+int cunt_pressed = 0.0;
+int cunt_released = 0.0;
+int x,y;
 
 void serial_callback()
 {
@@ -19,28 +19,32 @@
 
 void pressed()
 {
-    while(button=='0'){
-        cunt_pressed =  cunt_pressed+1;
-        if(cunt_released != 0)
+    if(cunt_released != 0)
         {
             y = cunt_released;
-            printf("released = %f\n",y);
+            modbus_update(0, y);
+             pc.printf("released = %d\n",y);
+            pc.printf("released = %d\n",modbus_read(0));
             cunt_released = 0;
         }
+    while(button==0){
+        cunt_pressed =  cunt_pressed+1;
         wait(0.1);
     }
 }
 
 void released()
 {
-    while(button=='1'){
-        cunt_released = cunt_released+1;
-        if(cunt_pressed != 0)
+     if(cunt_pressed != 0)
         {
             x = cunt_pressed;
-            printf("pressed = %f\n",x);
+            modbus_update(1, x);
+             pc.printf("pressed = %d\n",x);
+            pc.printf("pressed = %d\n",modbus_read(1));
             cunt_pressed = 0;
         }
+    while(button==1){
+        cunt_released = cunt_released+1;
         wait(0.1);
         }
 }
@@ -50,11 +54,11 @@
     pc.attach(serial_callback);
     
     // 1. button code
+    button.mode(PullNone); 
     button.fall(&pressed);  
     button.rise(&released);
     
     // 2. timer code
-    
     while(1) {
         // loop code
         myled = 1; // LED is ON