- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#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 */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It worked. Thank you.