2015_robocon_bteam / Mbed 2 deprecated 2015robot_main

Dependencies:   PID QEI mbed

Fork of 2015robot_main by Naoto Deguchi

Revision:
68:2b2b88ecdcce
Parent:
59:9d66edf3e734
Child:
69:bf094811b4a9
--- a/communicate.h	Wed Oct 07 09:01:34 2015 +0000
+++ b/communicate.h	Thu Oct 08 09:04:48 2015 +0000
@@ -7,6 +7,8 @@
 inline void initializeRS485(){
     RS485.format(8,Serial::Even);
 }
+
+/*
 inline void sendData(int address, int data5) {
     unsigned int data;
     if (data5 <= 31) {
@@ -14,6 +16,23 @@
         RS485.putc(data);
     }
 }
+*/
+
+inline void sendData(int address, unsigned int data8) {
+    unsigned int data;
+    if (data8 <= 15 && data8 >= 0) {
+        data = 128 | (address << 4) | (data8 & 15);
+        RS485.putc(data);
+    }
+    else if (data8 <= 255 && data8 >= 16) {
+        data = (address << 4) | (data8 >> 4);
+        RS485.putc(data);
+        wait(0.0001);
+        data = 128 | (address << 4) | (data8 & 15);
+        RS485.putc(data);
+    }
+}
+
 
 #ifdef IM920
 /***IM920 Communication.***/