You are here

Capsense on-off button | Cypress Semiconductor

Capsense on-off button

Summary: 37 Replies, Latest post by manusinh thakor on 29 Jul 2017 07:42 AM PDT
Verified Answers: 1
Last post
Log in to post new comments.
user_253382995's picture
User
28 posts

 Hi,

I am using CY8CKIT-001 - CY8CKIT-009. I have a problem.I want to use it as a single on-off capsense button. So when I press the button once will light up led,later I press the same capsense button again will turn off led. I use the following code:



if( statusButton0 == ON && onoff==0)



LCD_PrintString("On ");

Led1_Write(0x01);

onoff=1;

}





LCD_Position(1,3);

if( statusButton0 == ON && onoff==1)





CyDelay(200u);

LCD_PrintString("On");

onoff=0;

Led1_Write(0x00);

}



I do not know what I'm doing wrong but Led is flashing. Do you have a software error or hardware error? Thanks your answers.

hli
user_78878863's picture
User
2759 posts

I suppose that your CapSense button is always on. You should add debug code to gets its state. Then you can determine whether the CapSense handling is at fault, or your on-off logic.

Maybe you can upload your project here so we can have a complete look? (Use the 'File / Create Workspace Bundle').

user_253382995's picture
User
28 posts

 Thanks.I upload my design program.

user_253382995's picture
User
28 posts
user_14586677's picture
User
7648 posts

If I look at this code, if its in a loop, you start by turning led on,

then immeadiately turn the led off after a delay by setting onoff = 1,

so would be flashing. You need to test for status button turning back

to "0".

 

 

 

if( statusButton0 == ON && onoff==0) {

 
     LCD_PrintString("On ");
     Led1_Write(0x01);
     onoff=1;
}

LCD_Position(1,3);

if( statusButton0 == ON && onoff==1)

      CyDelay(200u);
      LCD_PrintString("On");
      onoff=0;
      Led1_Write(0x00);
}

 

Regards, Dana.

user_253382995's picture
User
28 posts

 ı try to upload program but ı I can not upload.

user_14586677's picture
User
7648 posts

Without seeing whole project code should look like ......

 

if( statusButton0 == ON && onoff==0) {

 
     LCD_PrintString("On ");
     Led1_Write(0x01);
     onoff=1;
}

 

LCD_Position(1,3);

 

if( statusButton0 == OFF && onoff==1)

      CyDelay(200u);
      LCD_PrintString("Off");
      onoff=0;
      Led1_Write(0x00);
}

 

Regards, Dana.

hli
user_78878863's picture
User
2759 posts

But the LED should not follow the button. I would write it as:

if (ON==statusButton0)
{
  if(0==onoff)
  {
    // switch it of
    onoff=1;
  }
  else
  {
    // switch it off
    onoff=0;
  }
}

user_253382995's picture
User
28 posts

 Hi Dana,

Thank you for answers, I tried to say the two code but  program give different results. I want the same push-button LED on - off .Finally I tried the following program; the problem here After pressing the button LED is on, but I need to push another button for  turning off  same push button

 

 if( slot_1 == 1 && onoff==0)

           

  {

  

LCD_PrintString("   On ");

LED1_Write(0x01);

Button_ON1 = 1;

                    }

else if (slot_1 == 0 && Button_ON1 == 1) 

{ onoff=1;

Button_ON1 = 0;

}

 

        if (slot_1 ==1 && onoff==1 )

        {

                

Button_ON2 = 1;

LED1_Write(LED_OFF);

        }

else if(slot_1 == 0  && Button_ON2 == 1)

{

onoff=0;

Button_ON2 = 0;

}

 

user_14586677's picture
User
7648 posts

Not sure I am following your logic goal -

 

If you push one button LED = on, and then when another button

pushed LED is turned off ? If so code would look like -

 

if ( button1 && !ledonflg) {

      // turn on led, set ledonflag, and print "On" on LCD

if ( button2 && ledonflag ) {

      // turn off led, clear ledonflag, and print "Off" on LCD

 

Regards, Dana.

user_253382995's picture
User
28 posts

 Hi Hli,

I try to your program logic to be true but no stability. program not work in the same way

Log in to post new comments.