cancel
Showing results for 
Search instead for 
Did you mean: 

Code Examples

Esteemed Contributor

Hi all,

The electronic dice I posted last time was very popular. Many people have requested that we make on PSoC 4 version, so I made it based on CY8CKIT-044. See previous post for more details on the design of the "PSoC 4 Seven Eyes Dice". Here, I will describe the addition of the design for sounding the piezoelectric buzzer.

1.png  

The environment used is as follows:

PSoC Creator 4.3

CY8CKIT-044

PWM (PWM_2) and piezoelectric buzzer (external) were added to the previous circuit. The circuit of PSoC4 is as follows.

2.png

 

The pin assignments are as follows.

3.png

 

The added PWM_2 inputs a 1MHz clock, and the settings are as follows.

4.png 

The program adds a start API for PWM_2.

#include "project.h"

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

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

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

    PWM_2_Start();

    for(;;)

    {

       if(sw==0){

           // if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==0){

            if(SW2_Read()==0){

                PWM_1_WritePeriod(400);

                PWM_1_WriteCounter(0);

                PWM_1_Start();  // Start rolling dice

                sw=1;

            }

        }

        if(sw==1){

            //if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==1){

            if(SW2_Read()==1){

                /* Roll dice slowly */

                PWM_1_WritePeriod(1000);

                PWM_1_WriteCounter(0);

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

                PWM_1_Stop();// Stop rolling dice                   

                sw=0;           // sw is off           

            }

        }

    }

}

Thanks,

Kenshow

1 Reply
Moderator
Moderator

Hi Kenshow-san,

Thank you for sharing your example project with the community.

Best regards,
Hari

0 Likes
Reply
Top labels