- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using CY8C4025AZI-S413 micro controller with PSoC 4.3 creator
I have configured 4 buttons and one proximity in single cap sense block in top design
I wrote code for the same but it is not executing
If i configured single button and write the same code, it is executing
But I want to turn on seperate 4 LED if any of the buttons 1,2,3,4 pressed and and release respective led if button is released along with key number to be displayed on UART
Please Refer my code:
/**********************************************************************************************************/
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
pwm_Start();
capsense1_Start();
capsense1_InitializeAllBaselines();
capsense1_ScanAllWidgets();
led17_Write(0);
for(;;)
{
/* Place your application code here. */
if(!CapSense_IsBusy())
{
CapSense_ProcessAllWidgets();
if (CapSense_IsAnyWidgetActive())
{
LED_1_Write(1);
}
else
{
LED_1_Write(0);
}
}
CapSense_UpdateAllBaselines();
CapSense_ScanAllWidgets();
}
}
/**********************************************************************************************************/
I should check button and proximity if buttons are enable, proximity should be disabled and vice versa
What should I do?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OOPS!
Since I was about to leave my office, I totally forgot about LEDs.
Following is main.c supporting 4 LEDs.
main.c
==============================
#include "project.h"
#include "stdio.h"
#if 1 // change to 0 if your LED turn on with LOW LEVEL
#define LED_ON (1u)
#define LED_OFF (0u)
#else
#define LED_ON (0u)
#define LED_OFF (1u)
#endif
#define STR_LEN 64
char str[STR_LEN+1] ; /* print buffer */
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
sprintf(str, "CapSense Test (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
CapSense_Start() ;
CapSense_ScanAllWidgets() ;
}
int main(void)
{
uint32_t button_state = 0 ;
uint32_t proximity_state = 0 ;
init_hardware() ;
splash() ;
for(;;)
{
if (CapSense_IsBusy() == CapSense_NOT_BUSY) {
CapSense_ProcessAllWidgets() ;
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS0_ID
) ;
if (button_state) { /* button pressed */
LED1_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button1: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED1_Write(LED_OFF) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS1_ID
) ;
if (button_state) { /* button pressed */
LED2_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button2: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED2_Write(LED_OFF) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS2_ID
) ;
if (button_state) { /* button pressed */
LED3_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button3: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED3_Write(LED_OFF) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS3_ID
) ;
if (button_state) { /* button pressed */
LED4_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button4: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED4_Write(LED_OFF) ;
}
proximity_state = CapSense_IsSensorActive(
CapSense_PROXIMITY0_WDGT_ID,
CapSense_PROXIMITY0_SNS0_ID
) ;
if (proximity_state) {
snprintf(str, STR_LEN, "Proximity: 0x%08X\n", proximity_state) ;
print(str) ;
}
CapSense_ScanAllWidgets();
}
}
}
==============================
Note: I have compiled this project but have not tested on a hardware.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
capsense1_Start();
capsense1_InitializeAllBaselines();
capsense1_ScanAllWidgets();
Are the above three functions customized based on the existing CapSense API ?
If it is, please share the customized source code or the entire project file.
Thank you,
Teddy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried with a TSoC Board, which has CY8C4146LQI-S433.
As I'm still learning about CapSense, and I'm sure this is NOT the most elegant implementation.
But it's somewhat working.
schematic
CapSense Config
Pins
main.c
==================
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ; /* print buffer */
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
sprintf(str, "CapSense Test (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
CapSense_Start() ;
CapSense_ScanAllWidgets() ;
}
int main(void)
{
uint32_t button_state = 0 ;
uint32_t proximity_state = 0 ;
init_hardware() ;
splash() ;
for(;;)
{
if (CapSense_IsBusy() == CapSense_NOT_BUSY) {
CapSense_ProcessAllWidgets() ;
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS0_ID
) ;
if (button_state) { /* button pressed */
snprintf(str, STR_LEN, "Button1: 0x%08X\n", button_state) ;
print(str) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS1_ID
) ;
if (button_state) { /* button pressed */
snprintf(str, STR_LEN, "Button2: 0x%08X\n", button_state) ;
print(str) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS2_ID
) ;
if (button_state) { /* button pressed */
snprintf(str, STR_LEN, "Button3: 0x%08X\n", button_state) ;
print(str) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS3_ID
) ;
if (button_state) { /* button pressed */
snprintf(str, STR_LEN, "Button4: 0x%08X\n", button_state) ;
print(str) ;
}
proximity_state = CapSense_IsSensorActive(
CapSense_PROXIMITY0_WDGT_ID,
CapSense_PROXIMITY0_SNS0_ID
) ;
if (proximity_state) {
snprintf(str, STR_LEN, "Proximity: 0x%08X\n", proximity_state) ;
print(str) ;
}
CapSense_ScanAllWidgets();
}
}
}
==================
Tera Term log
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OOPS!
Since I was about to leave my office, I totally forgot about LEDs.
Following is main.c supporting 4 LEDs.
main.c
==============================
#include "project.h"
#include "stdio.h"
#if 1 // change to 0 if your LED turn on with LOW LEVEL
#define LED_ON (1u)
#define LED_OFF (0u)
#else
#define LED_ON (0u)
#define LED_OFF (1u)
#endif
#define STR_LEN 64
char str[STR_LEN+1] ; /* print buffer */
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
sprintf(str, "CapSense Test (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
CapSense_Start() ;
CapSense_ScanAllWidgets() ;
}
int main(void)
{
uint32_t button_state = 0 ;
uint32_t proximity_state = 0 ;
init_hardware() ;
splash() ;
for(;;)
{
if (CapSense_IsBusy() == CapSense_NOT_BUSY) {
CapSense_ProcessAllWidgets() ;
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS0_ID
) ;
if (button_state) { /* button pressed */
LED1_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button1: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED1_Write(LED_OFF) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS1_ID
) ;
if (button_state) { /* button pressed */
LED2_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button2: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED2_Write(LED_OFF) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS2_ID
) ;
if (button_state) { /* button pressed */
LED3_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button3: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED3_Write(LED_OFF) ;
}
button_state = CapSense_IsSensorActive(
CapSense_BUTTON0_WDGT_ID,
CapSense_BUTTON0_SNS3_ID
) ;
if (button_state) { /* button pressed */
LED4_Write(LED_ON) ;
snprintf(str, STR_LEN, "Button4: 0x%08X\n", button_state) ;
print(str) ;
} else {
LED4_Write(LED_OFF) ;
}
proximity_state = CapSense_IsSensorActive(
CapSense_PROXIMITY0_WDGT_ID,
CapSense_PROXIMITY0_SNS0_ID
) ;
if (proximity_state) {
snprintf(str, STR_LEN, "Proximity: 0x%08X\n", proximity_state) ;
print(str) ;
}
CapSense_ScanAllWidgets();
}
}
}
==============================
Note: I have compiled this project but have not tested on a hardware.
moto