JBBoardに接続したモーター2つをRCBControllerでコントロールするテストです。

Dependencies:   FatFileSystem TB6612FNG2 mbed

Fork of JBB_BTLE_Test by Jksoft Blue mbed Board Developer

Revision:
7:3ed1e36587d4
Parent:
6:cf06ba884429
--- a/BLE_demo.cpp	Wed Feb 20 14:18:38 2013 +0000
+++ b/BLE_demo.cpp	Mon May 12 14:24:35 2014 +0000
@@ -61,7 +61,7 @@
 // mbed specific
 #include "mbed.h"
 Serial pc(USBTX, USBRX);
-DigitalOut led1(LED1), led2(LED2), led3(LED3);
+DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);;
 DigitalIn  sw1(p5);
 
 // from btstack ble_server.c
@@ -79,6 +79,10 @@
 #include "config.h"
 
 #include "att.h"
+#include "TB6612.h"
+
+TB6612 MOTOR_A(p21,p19,p20);            // PWM IN1 IN2
+TB6612 MOTOR_B(p22,p29,p30);            // PWM IN1 IN2
 
 hci_transport_t * hci_transport_picusb_instance();
 
@@ -248,11 +252,15 @@
     switch(handle) {
             // Correspond to Characteristics 0xFFF1
         case 0x000b:
+#if 0
             if(buffer && ret<=buffer_size) {
                 buffer[0] = sw1.read();
                 log_info("Read value: %u\n", buffer[0]);
             }
             ret = 1;
+#else
+            ret = 0;
+#endif
             break;
 
             // Correspond to Characteristics 0xFFF2
@@ -287,7 +295,43 @@
     switch(handle) {
             // Correspond to Characteristics 0xFFF1
         case 0x000b:
-            log_info("No action\n");
+            uint16_t game_pad;
+            game_pad = (buffer[0] << 8 ) | buffer[1];
+            //log_info("No action\n");
+            switch(game_pad)
+            {
+            case 0x0001:
+                MOTOR_A = 30;
+                MOTOR_B = 30;
+                break;
+            case 0x0002:
+                MOTOR_A = -30;
+                MOTOR_B = -30;
+                break;
+            case 0x0004:
+                MOTOR_A = 30;
+                MOTOR_B = -30;
+                break;
+            case 0x0008:
+                MOTOR_A = -30;
+                MOTOR_B = 30;
+                break;
+            case 0x0100:
+                led4 = !led4;
+                int x = (int)buffer[6] - 128;
+                if( (x > 5)||(x < -5) )
+                {
+                    x = x > 100 ? 100 : x; 
+                    x = x < -100 ? -100 : x; 
+                    MOTOR_A = x > 0 ? 100 - x : 100;
+                    MOTOR_B = x < 0 ? 100 + x : 100;
+                }
+            default:
+                MOTOR_A = 0;
+                MOTOR_B = 0;
+                break;
+            
+            }
             break;
 
             // Correspond to Characteristics 0xFFF2