Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_RCBController2_Motor by
Diff: main.cpp
- Revision:
- 7:45655ac58160
- Parent:
- 6:1aff9f05d487
- Child:
- 8:7ab6a5b29812
diff -r 1aff9f05d487 -r 45655ac58160 main.cpp --- a/main.cpp Fri Jan 01 00:38:30 2016 +0000 +++ b/main.cpp Wed Oct 11 21:05:02 2017 +0000 @@ -1,6 +1,8 @@ /* * December 31st, 2015 Modified by Kenji Arai - * January 1st, 2016 + * January 19th, 2016 + * October 12th, 2017 !! Run on Mbed-os5 without any modification + * (only these two lines + LED pin assign) * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * -> Works well with latest Rev. @@ -28,15 +30,21 @@ #define DEBUG(...) #endif -#define DIGITAL_OUT_PIN P0_17 //D7 -#define PWM_PIN P0_23 //D5 -#define SERVO_0_PIN P0_18 //D9 +#define LED_A_PIN P0_21 +#define LED_B_PIN P0_22 +#define LED_X_PIN P0_23 +#define LED_Y_PIN P0_24 +#define SERVO_0_PIN P0_18 +#define SERVO_1_PIN P0_16 // Object ---------------------------------------------------------------------------------------- BLE ble; Servo SERVO_0(SERVO_0_PIN); -DigitalOut LED_SET(DIGITAL_OUT_PIN); -PwmOut PWM(PWM_PIN); +Servo SERVO_1(SERVO_1_PIN); +DigitalOut LED_A(LED_A_PIN); +DigitalOut LED_B(LED_B_PIN); +DigitalOut LED_X(LED_X_PIN); +DigitalOut LED_Y(LED_Y_PIN); // RAM ------------------------------------------------------------------------------------------- uint8_t RCBControllerPayload[10] = {0,}; @@ -60,21 +68,48 @@ // Control Program //------------------------------------------------------------------------------------------------- void data_analysis(void){ - static uint8_t cont_flg = 0; + static uint8_t cont_flg_A = 0; + static uint8_t cont_flg_B = 0; + static uint8_t cont_flg_X = 0; + static uint8_t cont_flg_Y = 0; float value; + if (controller.status.A == 1){ + if (cont_flg_A == 0){ + LED_A = !LED_A; + cont_flg_A = 1; + } + } else { + cont_flg_A = 0; + } if (controller.status.B == 1){ - if (cont_flg == 0){ - LED_SET = !LED_SET; - cont_flg = 1; + if (cont_flg_B == 0){ + LED_B = !LED_B; + cont_flg_B = 1; } } else { - cont_flg = 0; + cont_flg_B = 0; + } + if (controller.status.X == 1){ + if (cont_flg_X == 0){ + LED_X = !LED_X; + cont_flg_X = 1; + } + } else { + cont_flg_X = 0; } - value = (float)controller.status.LeftAnalogLR/255; - PWM = value; + if (controller.status.Y == 1){ + if (cont_flg_Y == 0){ + LED_Y = !LED_Y; + cont_flg_Y = 1; + } + } else { + cont_flg_Y = 0; + } value = (float)controller.status.LeftAnalogUD/255 * 150.0f + 20; - SERVO_0.write(value); + SERVO_0.write(value); + value = (float)controller.status.LeftAnalogLR/255 * 150.0f + 20; + SERVO_1.write(value); } void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){ @@ -110,7 +145,8 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)deviceName, strlen(deviceName)); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, - (const uint8_t *)RCBController_service_uuid, sizeof(RCBController_service_uuid)); + (const uint8_t *)RCBController_service_uuid, + sizeof(RCBController_service_uuid)); ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ ble.startAdvertising(); ble.addService(RCBControllerService);