- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @Hari ,
I am using CY8c4245AXI-483 PSoC4 family MCU. I have implemented button and slider capsense functionality. For the touch button, I have implemented a functionality which changes the state of the button when the key is released. It is working fine but currently, I have been facing an issue with the slider. I need certain reference on how to implement a function which will change the state of slider key when it is released as I am sending a command to underlying MCU based on touch detection.
Solved! Go to Solution.
- Labels:
-
PSoC 4 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I also played with my CY8CKIT-042 😉
When I touch the slider the Green LED lights and changes the strength depending on the position.
When I release my finger the Blue LED lights.
Schematic
Pins
main.c
#include "project.h"
#define LED_ON 0u
#define LED_OFF 1u
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
LED_B_Write(LED_OFF) ;
LED_R_Write(LED_OFF) ;
EZI2C_Start() ;
/* Set up communication data buffer to CapSense data structure to be exposed to
I2C master at primary slave address request. */
EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),
(uint8 *)&CapSense_dsRam);
/* Start CapSense block - Initializes CapSense Data structure and
performs first scan to set up sensor baselines */
CapSense_Start();
PWM_Start() ;
/* Scan all widgets */
CapSense_ScanAllWidgets();
}
void set_pwm_duty(uint16_t duty)
{
uint16_t period ;
uint32_t work ;
period = PWM_ReadPeriod() ;
work = duty * period / 100 ;
if (work > period) {
work = period ;
}
PWM_WriteCompare(work) ;
PWM_WriteCounter(0) ;
}
int main(void)
{
uint16_t duty = 0 ;
init_hardware() ;
for(;;)
{
if (CapSense_NOT_BUSY == CapSense_IsBusy()) {
CapSense_ProcessAllWidgets() ;
CapSense_RunTuner() ;
if (CapSense_IsWidgetActive(CapSense_LINEARSLIDER0_WDGT_ID)) {
LED_B_Write(LED_OFF) ;
duty = 0 ;
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS0_ID)) {
duty += 5 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS1_ID)) {
duty += 10 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS2_ID)) {
duty += 15 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS3_ID)) {
duty += 30 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS4_ID)) {
duty += 40 ;
}
set_pwm_duty(duty) ;
} else { /* Liner Slider is not touched */
LED_B_Write(LED_ON) ;
set_pwm_duty(0) ;
}
CapSense_ScanAllWidgets() ;
}
}
}
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @saurabh,
You can refer to the following code example- CE210289 – PSoC®4 CapSense® Linear Slider.
Regards,
Nikhil
- 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
Hi,
I also played with my CY8CKIT-042 😉
When I touch the slider the Green LED lights and changes the strength depending on the position.
When I release my finger the Blue LED lights.
Schematic
Pins
main.c
#include "project.h"
#define LED_ON 0u
#define LED_OFF 1u
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
LED_B_Write(LED_OFF) ;
LED_R_Write(LED_OFF) ;
EZI2C_Start() ;
/* Set up communication data buffer to CapSense data structure to be exposed to
I2C master at primary slave address request. */
EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),
(uint8 *)&CapSense_dsRam);
/* Start CapSense block - Initializes CapSense Data structure and
performs first scan to set up sensor baselines */
CapSense_Start();
PWM_Start() ;
/* Scan all widgets */
CapSense_ScanAllWidgets();
}
void set_pwm_duty(uint16_t duty)
{
uint16_t period ;
uint32_t work ;
period = PWM_ReadPeriod() ;
work = duty * period / 100 ;
if (work > period) {
work = period ;
}
PWM_WriteCompare(work) ;
PWM_WriteCounter(0) ;
}
int main(void)
{
uint16_t duty = 0 ;
init_hardware() ;
for(;;)
{
if (CapSense_NOT_BUSY == CapSense_IsBusy()) {
CapSense_ProcessAllWidgets() ;
CapSense_RunTuner() ;
if (CapSense_IsWidgetActive(CapSense_LINEARSLIDER0_WDGT_ID)) {
LED_B_Write(LED_OFF) ;
duty = 0 ;
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS0_ID)) {
duty += 5 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS1_ID)) {
duty += 10 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS2_ID)) {
duty += 15 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS3_ID)) {
duty += 30 ;
}
if (CapSense_IsSensorActive(CapSense_LINEARSLIDER0_WDGT_ID, CapSense_LINEARSLIDER0_SNS4_ID)) {
duty += 40 ;
}
set_pwm_duty(duty) ;
} else { /* Liner Slider is not touched */
LED_B_Write(LED_ON) ;
set_pwm_duty(0) ;
}
CapSense_ScanAllWidgets() ;
}
}
}
moto