Let's make LED roulette on PSoC 4

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

cross mob
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi all,

In order to study how to turn on and control many LEDs, I created a board with a matrix. I decided to make a roulette wheel using 36 LEDs.

The environment used is as follows:

PSoC Creator 4.3

CY8CKIT-044

36 LEDs are mounted on the Arduino board, and 12 GPIOs are used to configure a 6x6 matrix. The circuit looks like this:

  1.png

The actual Arduino board was made as shown in the picture below. There were quite a lot of wiring and it got messed up.

   2.png3.png

The circuit creates a counter to count 6 by combining the components of Coutner and Compare in column side. It is used to select the De-Multiplexer to select the output.

The row side of the LED matrix is ​​counted after 6 counts. As a result, the lighting of a LED moves to shift like a roulette. The circuit and pin layout are as follows.

  1.png

  2.png

Press the SW2 switch to rotate the roulette wheel, and release it to slow down and stop.

The program is as follows:

#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(399);

                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(800);

                PWM_1_WriteCounter(0);

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

                PWM_1_WritePeriod(2000);

                PWM_1_WriteCounter(0);

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

                PWM_1_WritePeriod(4000);

                PWM_1_WriteCounter(0);

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

                PWM_1_WritePeriod(8000);

                PWM_1_WriteCounter(0);

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

                PWM_1_Stop();// Stop rolling

                sw=0;           // sw is off           

            }

        }

    }

}

When you press the SW2 switch, the roulette wheel rotates, and when you release it, it gradually stops slowly.

3.png 

Thanks,

Kenshow

 

5 Replies
Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Dear Kenshow-san,

Thank you very much for your contribution of CE.

Best regards.

lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

I updated this program as follows:

PSoC Creator 4.4 from 4.3

・Swapping function was used to switch the PWM period naturally

I checked the swap of period  in the PWM_1 configuration.

2.png

The program is as follows:

#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()) */

    for(;;)

    {

       if(sw==0){

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

            if(SW2_Read()==0){

                PWM_1_WritePeriod(399);

                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_WritePeriodBuf(1999);

                PWM_1_TriggerCommand(1, PWM_1_CMD_CAPTURE);

                CyDelay(1000);  // keep rolling slowly for 1sec

                PWM_1_WritePeriodBuf(3999);

                PWM_1_TriggerCommand(1, PWM_1_CMD_CAPTURE);

                CyDelay(1000);  // keep rolling slowly for 1sec                                  

                PWM_1_WritePeriodBuf(7999);

                PWM_1_TriggerCommand(1, PWM_1_CMD_CAPTURE);

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

                PWM_1_Stop();   // Stop rolling

                sw=0;           // sw is off           

            }

        }

    }

}

Thanks,

Kenshow

AlanH_86
Employee
Employee
100 replies posted 50 replies posted 25 solutions authored

I did some code like this as well a couple of years ago...

https://iotexpert.com/pinball-matrix-leds-part-1/

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

Hi,

Thanks for your good information.

In a general microcomputer design, the LED is controlled by software as shown on the web you pointed out. However, in the case of PSoC, the feature is that it can be implemented using hardware (UDB). This will relieve the CPU load.

The part that gradually slows down the PWM was controlled by software in this time, but in combination with the timer, this can also be replaced with hardware (although it is a little difficult).

There are various approaches to the program, so I hope you can see it as one of the designs. Of course, information like your indication one is also welcome.

Thanks,

Kenshow

0 Likes
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

I am going to post a program using DMA as another approach.

Thanks,

Kenshow