I can toggle LED using NEC IR remote , But i want change toggled button without change in code

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

cross mob
iammyur
Level 1
Level 1
10 sign-ins 5 sign-ins First reply posted

Hi @MotooTanaka ,

I can toggle LED using NEC IR remote , But i want change toggled button without change in code. can you please help me how can i do it 

Thanks ,

Mayur B.

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I assumed that your question is adding LED toggle by an external button function

without breaking your working IR remote control.

So I created a simple sample using CY8CKIT-044, with a button (SW2: P0[7]) and LED (P2[6]).

If you are using P0[x] for IR input,  use different port,

such as P1[x] ~ to avoid complicated interrupt handling may be a  good idea.

Please also note that I did not pay attention to debounce of the button.

You may want to use a component debouncer to take care of it.

Schematic

001-schematic.JPG

Pins

002-Pins.JPG

main.c

#include "project.h"

#define LED_ON  0u
#define LED_OFF 1u

void toggle_led(void)
{
    if (LED_Read() == LED_ON) {
        LED_Write(LED_OFF) ;
    } else {
        LED_Write(LED_ON) ;
    }
}

CY_ISR(button_isr)
{
    button_ClearInterrupt() ;
    toggle_led() ;
}

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    button_ClearInterrupt() ;
    isr_1_StartEx(button_isr) ;
    
    for(;;)
    {
        /* BLE Remote control part */
    }
}

moto

View solution in original post

0 Likes
3 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi Mayur,

Is this thread with respect to any previous thread ? If yes kindly point us  to that. Additionally could you elaborate your requirement ?

Best Regards,
Vasanth

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I assumed that your question is adding LED toggle by an external button function

without breaking your working IR remote control.

So I created a simple sample using CY8CKIT-044, with a button (SW2: P0[7]) and LED (P2[6]).

If you are using P0[x] for IR input,  use different port,

such as P1[x] ~ to avoid complicated interrupt handling may be a  good idea.

Please also note that I did not pay attention to debounce of the button.

You may want to use a component debouncer to take care of it.

Schematic

001-schematic.JPG

Pins

002-Pins.JPG

main.c

#include "project.h"

#define LED_ON  0u
#define LED_OFF 1u

void toggle_led(void)
{
    if (LED_Read() == LED_ON) {
        LED_Write(LED_OFF) ;
    } else {
        LED_Write(LED_ON) ;
    }
}

CY_ISR(button_isr)
{
    button_ClearInterrupt() ;
    toggle_led() ;
}

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    button_ClearInterrupt() ;
    isr_1_StartEx(button_isr) ;
    
    for(;;)
    {
        /* BLE Remote control part */
    }
}

moto

0 Likes
iammyur
Level 1
Level 1
10 sign-ins 5 sign-ins First reply posted

No , Sir .

I am talking about how can i change IR remote button for toggle the LED with out change in code .

Assume first i am toggling the LED using Button 1 from IR remote .

If i am press button 2 for long time example for 5 sec . LED should be toggle using button 2 .

it is possible ??

@MotooTanaka @Vasanth 

0 Likes