Button application

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
BUTA_1301626
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

I want the light to stay on when I press the button. I want the led to go off when I press the button again.I made the program using pin-interrupt. But I just want to do it by writing code.I would like to have only 1 pin and 1 led on TopDesign page.

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You already only have got one pin for the switch and one pin for the LED. With fewer components it will not work. De-bouncing and pin-toggling you can do in software. Configure your pin without interrupt and hardware connection. Remember that the blue components and wires are just for documentation an do not represent any existing parts.

   

 

   

Bob

View solution in original post

0 Likes
5 Replies
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

Yes,it is possible to do so in firmware.But it is not best solution to do so.

   

You may have to use a Debouncer Component with the button.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You already only have got one pin for the switch and one pin for the LED. With fewer components it will not work. De-bouncing and pin-toggling you can do in software. Configure your pin without interrupt and hardware connection. Remember that the blue components and wires are just for documentation an do not represent any existing parts.

   

 

   

Bob

0 Likes
BUTA_1301626
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

#include "project.h"

   

int prev = 0;

   

int current=0;

   

int main(void)

   

{  

   

    CyGlobalIntEnable; /* Enable global interrupts. */

   

     for(;;)

   

      {

   

while(1)

   

{

   

current =sw_Read();

   

if(current == 0 && current != prev)

   

{

   

Pin_Write(!Pin_Read());

   

CyDelay(5);

   

}

   

prev = current;

   

}          }}   /* [] END OF FILE */

Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Poorly commented and not well indented...

   

What are you telling us with the above code snippet? Does it work as expected?? Doesn't it???

   

 

   

Bob

0 Likes
BUTA_1301626
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

It worked. Thank you.

0 Likes