Using SHIFT key to double buttons

Hello!

I would like to learn how to do a simple IR REMOTE CONTROL keyboard with several buttons and one SHIFT-key. I would use the SHIFT key to double the buttons.

The problem I'm having with own simple code is that when I press the SHIFT-key and BUTTON 1, it also activates the BUTTON 1 at the same time and it should not do that. How to get rid of this?

Could someone write me a simple code to demonstrate how to do this?

Are there any tutorials available for this? I haven't find any yet.

Here's my simple code:



#include <IRremote.h>

IRsend irsend;

const int button1  = 1;
const int button2  = 2;
const int button3  = 3; // SHIFT


void setup() {
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);

}

void loop() {
    if (digitalRead(button1) == HIGH) 
    {
      irsend.sendNEC(0x000001, 32);     // BUTTON 1
    }
    
    if (digitalRead(button2) == HIGH) 
    {
      irsend.sendNEC(0x000002, 32);     // BUTTON 2
    }

    if (digitalRead(button3) == HIGH && digitalRead(button1) == HIGH) 
    {
      irsend.sendNEC(0x000003, 32);     // SHIFT + BUTTON 1
    }

    if (digitalRead(button3) == HIGH && digitalRead(button2) == HIGH) 
    {
      irsend.sendNEC(0x000004, 32);     // SHIFT + BUTTON 2
    }
}

Thanks!
, Pete.

Hi Pete,

Both codes get sent because the conditions for both are true. So you haven't got the conditions correct.

It's only one small change. Have another try, I'm sure you'll get it pretty easily.

Paul

To make it even more clear, this condition is true regardless of the state of button 3 (your shift key I assume) - ie the if will go through wether you press or not on button 3

same applies to button2

BTW

Always show us a good schematic of your proposed circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.

No, I cannot figure it out myself. Do I need to use nested IF-ELSE somehow? Please, help. Thanks.

What changes have you tried? Please describe them and what results you saw.

Yes, it should do that because that's what your code says it should do. It's quite simple code and easy to follow. Code is not "magic", it's just a list of simple instructions.

Read your code in loop(), line by line, and follow the list of instructions in your head. What conditions are checked? What are the inputs? What is the result? What code line will be executed next?

That might improve your code later, but you don't need to change the structure you have now, just fix the conditions in your existing if statements.

why do you have two conditions in this test?

would it make sense to have two conditions too in that one?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.