- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
The pin assignments are as follows.
The settings of the CapSense component used in CE of CY8CKIT_044_CapSense_Proximity are used as they are.
The settings are as follows.
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
- Labels:
-
PSoC 345 LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content