Attachments are accessible only for community members.
Mar 08, 2021
10:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 08, 2021
10:36 PM
Hi,
This is a simple sample of using CapSense [v7.0] for 2 buttons operation using CY8CKIT-042.
Although this is a quite simple sample, may be somewhat useful for those who is not familiar with writing C program(s),
such as the discussion below.
I assigned the node P1.5 as "Up" button and P1.1 as "Down" button.
schematic
CapSense Config
Pins
Since I don't have many LEDs on my CY8CKIT-042,
I let UART write "*" instead of LEDs.
main.c
==========================
#include "project.h"
#include "stdio.h"
#define MAX_LED_COUNT 4
#define MIN_LED_COUNT 0
#define STR_BUF_LEN 32
char str[STR_BUF_LEN+1] ;
void print(char *str)
{
UART_PutString(str) ;
}
void cls(void)
{
print("\x1b[2J\x1b[;H") ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
cls() ;
CapSense_Start() ;
CapSense_ScanAllWidgets() ;
}
void do_led(int led_count)
{
switch(led_count) {
case 0: /* MIN_LED_COUNT? */
/* turn off all LEDs */
cls() ;
break ;
case 1:
/* turn on only 1 LED */
cls() ;
print("*\n\r") ;
break ;
case 2:
/* turn on 2 LEDs */
cls() ;
print("* *\n\r") ;
break ;
case 3:
/* turn on 3 LEDs */
cls() ;
print("* * *\n\r") ;
break ;
case 4: /* MAX_LED_COUNT? */
/* turn on 4 LEDs */
cls() ;
print("* * * *\n\r") ;
break ;
default:
/* do nothing */
break ;
}
}
int main(void)
{
int led_count = 0 ;
init_hardware() ;
for(;;)
{
if (CapSense_NOT_BUSY == CapSense_IsBusy()) {
CapSense_ProcessAllWidgets() ;
if (CapSense_IsAnyWidgetActive()) {
if (CapSense_IsSensorActive(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS0_ID)) {
led_count++ ;
if (led_count > MAX_LED_COUNT) {
led_count = MAX_LED_COUNT ;
}
} else if (CapSense_IsSensorActive(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS1_ID)) {
led_count-- ;
if (led_count < MIN_LED_COUNT) {
led_count = MIN_LED_COUNT ;
}
}
do_led(led_count) ;
}
CyDelay(100) ;
CapSense_ScanAllWidgets() ;
}
}
}
==========================
moto
Labels
- Labels:
-
CapSense
-
CY8CKIT-042
-
ispn:39611:1:0
-
l1:314:1:0
-
PSoC4
6 Replies