cancel
Showing results for 
Search instead for 
Did you mean: 

Code Examples

Kenshow
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. I have also
created a new LED lighting board. This time it is based on Arduino.

1.png


The environment used is as follows:

PSoC Creator 4.3

CY8CKIT-044

The block diagram of the hardware is same as LED Test. The H/W block diagram is shown below.

2.png

Once the H/W check posted last time is completed, the electronic dice will be completed by changing the decoding circuit, adding SW, and changing the program. Please refer to the previous article for LED wiring and pin assignment. The circuit on PSoC 4 is as follows.


3.png

Pin SW2 is Input and Pull Up. Read the value programmatically with GPIO input.


4.png

The pin assignments are as follows.


5.png

The PWM is set earlier than last time. Actually, the program is more effective.


6.png

When the SW2 button is pressed, the dice start to roll, and when they are released, the dice slows down the rolling and stops.

#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_1_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

0 Replies