JBBoardに接続したモーター2つをRCBControllerでコントロールするテストです。
Dependencies: FatFileSystem TB6612FNG2 mbed
Fork of JBB_BTLE_Test by
Revision 7:3ed1e36587d4, committed 2014-05-12
- Comitter:
- jksoft
- Date:
- Mon May 12 14:24:35 2014 +0000
- Parent:
- 6:cf06ba884429
- Commit message:
- First edition
Changed in this revision
--- 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
--- a/BTstack/profile.h Wed Feb 20 14:18:38 2013 +0000 +++ b/BTstack/profile.h Mon May 12 14:24:35 2014 +0000 @@ -26,9 +26,9 @@ // 0x0009 PRIMARY_SERVICE-FFF0 0x0a, 0x00, 0x02, 0x00, 0x09, 0x00, 0x00, 0x28, 0xf0, 0xff, // 0x000a CHARACTERISTIC-FFF1-READ | DYNAMIC - 0x0d, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x03, 0x28, 0x02, 0x0b, 0x00, 0xf1, 0xff, + 0x0d, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x03, 0x28, 0x04, 0x0b, 0x00, 0xf1, 0xff, // 0x000b VALUE-FFF1-READ | DYNAMIC- - 0x08, 0x00, 0x02, 0x01, 0x0b, 0x00, 0xf1, 0xff, + 0x08, 0x00, 0x04, 0x01, 0x0b, 0x00, 0xf1, 0xff, // 0x000c CHARACTERISTIC-FFF2-READ | WRITE | DYNAMIC 0x0d, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x03, 0x28, 0x0a, 0x0d, 0x00, 0xf2, 0xff, // 0x000d VALUE-FFF2-READ | WRITE | DYNAMIC-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TB6612FNG2.lib Mon May 12 14:24:35 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/jksoft/code/TB6612FNG2/#051a7ecff13e