Let's make the dice of seven eyes using on PSoC 4 with a proximity sensor,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,

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" and “PSoC 4 Seven Eyes Dice with sound”. Here, I will describe using a proximity sensor instead of a switch.

1.png 

The environment used is as follows:

PSoC Creator 4.3

CY8CKIT-044

CapSence for proximity sensor is added to the previous circuit. The circuit of PSoC4 is as follows.

  2.png

The pin assignments are as follows.

  3.png

The settings of the CapSense component used in CE of CY8CKIT_044_CapSense_Proximity are used as they are.

The settings are as follows.

  4.png

  5.png

  6.png

  7.png

The program adds CapSense Proximity instead of SW2.

#include "project.h"

/*****************************************************************************

* MACRO Definition

*****************************************************************************/

#define FALSE                                    0x00

#define TRUE                                     0x01

/* 4 ILO periods expressed in microseconds. */

#define ILOX4                                    ((4 * 1000) / 32)

#define INACTIVE                                 0

#define ACTIVE                                          1

#define RESET                                    0

/* MAX_VALUE defined to achieve 3 second duration.

* See the explanation for variable softCounter in main.c. */

#define MAX_VALUE                                100

#define ZERO                                     0x00

#define OFF                                             0x00

#define ON                                              0x01

#define PROX_UPPER_LIMIT                  55000

#define PROX_LOWER_LIMIT                  CapSense_SensorBaseline[0]

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

int main(void)

{

        /* Proximity sensor state. */

       uint8 proximity  = INACTIVE;

    CyGlobalIntEnable; /* Enable global interrupts. */

        /* Enable and start the CapSense block. */

       CapSense_Start();

       /* Initialize the baselines of all CapSense widgets. */

       CapSense_InitializeSensorBaseline(CapSense_PROXIMITYSENSOR__PROX);

       /* Enable and start PWM block. */

    PWM_2_Start();

    for(;;)

    {

        /* Update the baseline of the proximity sensor. */

              CapSense_UpdateSensorBaseline(CapSense_PROXIMITYSENSOR__PROX);

              /* Scan the proximity sensor. */

              CapSense_ScanSensor(CapSense_PROXIMITYSENSOR__PROX);

        while(CapSense_IsBusy())

              {

                     /* Put the PSoC 4200M in Sleep power mode while the CapSense is scanning.

                      * The device wakes up using the interrupt generated by CapSense CSD Component

                      * after scanning. */

              }

              /* Check if proximity sensor is active. */

              proximity = CapSense_CheckIsSensorActive(CapSense_PROXIMITYSENSOR__PROX);

              if(proximity == ACTIVE)

              {

                     /* Set the LED at a brightness level corresponding

                      * to the proximity distance. */

            if(sw==0){

                PWM_1_WritePeriod(400);

                PWM_1_WriteCounter(0);

                PWM_1_Start();  // Start rolling dice

                sw=1;

            }

        }

              else /* Proximity sensor is inactive. */

              {

            if(sw==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   

            }

              } 

    }

}

The dice rolls when you hold your hand over the proximity sensor, and the dice slowly rolls when you move it away, and then stops.

Thanks,

Kenshow

2 Replies
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi NoriakiT_91​,

Awesome! Thanks for your contribution

Regards,

Bragadeesh

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

Hi

I noticed that the decoding logic part of the circuit I posted last time can reduce the inverter part. I will post the modified version here.

8.png

Thanks,

Kenshow