- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I made a program to control electronic dice from BLE. The remote control side of BLE used the program of Central that I posted previously as it was, and controlled the start and stop of the dice by the movement of the slider. In the photo, the top is the electronic dice and the bottom is the remote control. The remote control below is connected to the mobile battery to supply power.
The environment used is as follows:
・PSoC Creator 4.2
・CY8CKIT-062-BLE
As for the circuit of the dice, I did not like the circuit I posted last time, so I returned it to the previous one and added the BLE component. Please refer to the previous post for LED placement. The circuit and the pin assignment in PSoC6 are as follows.
The program of BLE event handler is as follows:
void genericEventHandler(uint32_t event, void *eventParameter)
{
cy_stc_ble_gatts_write_cmd_req_param_t *writeReqParameter;
/* Take an action based on the current event */
switch (event)
{
/* This event is received when the BLE stack is Started */
case CY_BLE_EVT_STACK_ON:
case CY_BLE_EVT_GAP_DEVICE_DISCONNECTED:
PWM_BLINK_Start();
Cy_BLE_GAPP_StartAdvertisement(CY_BLE_ADVERTISING_FAST, CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX);
break;
case CY_BLE_EVT_GATT_CONNECT_IND:
Cy_TCPWM_TriggerReloadOrIndex(PWM_BLINK_HW,PWM_BLINK_CNT_NUM);
Cy_TCPWM_PWM_Disable(PWM_BLINK_HW,PWM_BLINK_CNT_NUM);
break;
case CY_BLE_EVT_GATTS_WRITE_REQ:
writeReqParameter = (cy_stc_ble_gatts_write_cmd_req_param_t *)eventParameter;
if((CY_BLE_LED_GREEN_CHAR_HANDLE == writeReqParameter->handleValPair.attrHandle) ||
(CY_BLE_LED_BLUE_CHAR_HANDLE == writeReqParameter->handleValPair.attrHandle))
{
val = writeReqParameter->handleValPair.value.val[0];
if(val>100) val = 100;
if(val>valp){
PWM_1_SetCounter(0);
PWM_1_SetPeriod0(399);
PWM_1_Start(); // Start rolling dice
sw=1; // sw is on
valp = val;
}
if(val<valp){
/* Roll dice slowly */
PWM_1_SetCounter(0);
PWM_1_SetPeriod0(1999);
CyDelay(1500); // keep rolling slowly for 1.5sec
PWM_1_Disable();// Stop rolling dice
sw=0; // sw is off
valp=0;
}
}
Cy_BLE_GATTS_WriteRsp(writeReqParameter->connHandle);
break;
default:
break;
}
}
Reference information
- Concept of electronic dice: Let's make the dice of seven eyes with PSoC 6 (M4), the protagonist of the game
- PSoC 6 BLE controller (This Code Example is PSoC6_LED_BleCentral.cyfsn.zip):BLE demo using 2 kits
- PSoC 6 Electronic Dice (previous post): Let's make the dice of seven eyes on PSoC 6 with CapSense & sound,the protagonist of the game
Thanks,
Kenshow
- Labels:
-
PSoC 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content