Let's make the dice of seven eyes on PSoC 6 with BLE,the protagonist of the game

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

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.

1.png  

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.

2.png

  3.png

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

Thanks,

Kenshow

1 Reply
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello NoTa_4591161 ,

Thank you for sharing the code example in the community.

Thanks,

P Yugandhar.

0 Likes