cancel
Showing results for 
Search instead for 
Did you mean: 

Code Examples

Esteemed Contributor

Hi all,

I created a new Arduino board for lighting LEDs on PSoC 4, so I also deployed it on PSOC6. I had a counter available in PSoC 4, but I didn't find a similar component in PSoC 6. Instead, there was a down counter, so I changed to a circuit design using that. 

  1.png2.png3.png

The environment used is as follows:

PSoC Creator 4.2

CY8CKIT-062-BLE

The components are placed on the PSoC 6 kit so that sound and CapSense can be used. The decoding circuit has also been simplified. The circuit of PSoC6 is as follows.

  4.png

The pin assignments are as follows.

5.png

  6.png

The program on CM4 is as follows:

//#define SW2 // If you want to use sw2 instad of Capsense, uncomment this line.

#include "project.h"

uint32_t sw=0;  //sw is off (Stop rolling dicce)

int main(void)

{

    __enable_irq(); /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    Clock_Enable() ;

#ifndef SW2

    CapSense_Start();

    CapSense_ScanAllWidgets(); // Start Initial Scan

#endif

    Count7_1_Start();

    for(;;)

    {

#ifdef SW2 

        if(sw==0){

if(Cy_GPIO_Read(SW2_0_PORT,SW2_NUM)==0){

                Timer_SetPeriod(400);

                Timer_SetCounter(0);

                Timer_Start();  // Start rolling dice

                sw=1;

            }

        }

        if(sw==1){

            if(Cy_GPIO_Read(SW2_0_PORT,SW2_NUM)==1){

                /* Roll dice slowly */

                Timer_SetPeriod(2000);

                Timer_SetCounter(0);

                CyDelay(1500);  // keep rolling slowly for 1.5sec

                Timer_Disable();// Stop rolling dice                   

                sw=0;           // sw is off           

            }

        }

#else

        if(!CapSense_IsBusy())

        {

            CapSense_ProcessAllWidgets();

           

            if(sw==0){ // If sw is on, check start botton0.

                if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)) // Check button 0 state

                {

                    /* Start rolling dice*/

                    PWM_1_SetCounter(0);

                    PWM_1_SetPeriod0(399);

                    //PWM_1_SetCompare0(200);

                    PWM_1_Start();  // Start rolling dice

                    PWM_2_Start();

                    sw=1; // sw is on

                }

            }

           

            if(sw==1){ // If sw is on, check stop botton0.

                if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID)) // Check button 1 state

                {

                    /* Roll dice slowly */

                    PWM_1_SetCounter(0);

                    PWM_1_SetPeriod0(1999);

                    //PWM_1_SetCompare0(200);

                    CyDelay(1500); // keep rolling slowly for 1.5sec

                    PWM_1_Disable();// Stop rolling dice                   

                    PWM_2_Disable();

                    sw=0;           // sw is off

                }

            }

           

            CapSense_UpdateAllBaselines();

            CapSense_ScanAllWidgets(); // Start next scan

        }

#endif

    }

}

/* [] END OF FILE */

Reference information

Thanks,

Kenshow

1 Reply
Moderator
Moderator

Hello Kenshow-san,

Thank you for sharing this project with the community.

Top labels