Attiny85 program IRremote

Hello, I want to make a code for attiny85 with 6 buttons where button one is connected to PIN 1, button 2 is connected to PIN 2, buttons 3 and 4 are connected to PIN 3, buttons 5 and 6 are connected to PIN 4. Create a program so that you don't get confused when you make a mistake. one of buttons 3 and 4 or buttons 5 and 6 is pressed without confusion. When one of the buttons is pressed it will send a hex code to the remote where pin 0 is used for the IR LED to send the hex code. Where buttons 3 and 4 each have a 1k resistor connected in parallel, similarly buttons 5 and 6 each have a 1k resistor connected in parallel, button 1 has a 1k resistor and button 2 has a 1k resistor.

Can anyone help me?

What is the point to have a two buttons connected to the same pin?

That would help all of us...

1 Like

because I have 6 buttons and 1 pin is used for the IR led, do you have any suggestions?

#include <IRremote.h>

#define IR_PIN 0 // PB0 on ATtiny85 is pin 0 on Arduino IDE

IRsend irsend;

#define BUTTON1_PIN 1 // PB1 on ATtiny85 is pin 1 on Arduino IDE
#define BUTTON2_PIN 2 // PB2 on ATtiny85 is pin 2 on Arduino IDE
#define BUTTON3_PIN 3 // PB3 on ATtiny85 is pin 3 on Arduino IDE
#define BUTTON4_PIN 3 // PB3 on ATtiny85 is pin 3 on Arduino IDE
#define BUTTON5_PIN 4 // PB4 on ATtiny85 is pin 4 on Arduino IDE
#define BUTTON6_PIN 4 // PB4 on ATtiny85 is pin 4 on Arduino IDE

bool button3Pressed = false;
bool button5Pressed = false;

void setup() {
    // Inisialisasi pin sebagai input tanpa pull-up internal
    pinMode(BUTTON1_PIN, INPUT_PULLUP);
    pinMode(BUTTON2_PIN, INPUT_PULLUP);
    pinMode(BUTTON3_PIN, INPUT_PULLUP);
    pinMode(BUTTON4_PIN, INPUT_PULLUP);
    pinMode(BUTTON5_PIN, INPUT_PULLUP);
    pinMode(BUTTON6_PIN, INPUT_PULLUP);

    // Inisialisasi IR
    irsend.begin(IR_PIN);
}

void loop() {
    if (digitalRead(BUTTON1_PIN) == LOW) {
        irsend.sendNEC(0xFFA25D, 32);  // Ganti dengan kode yang sesuai untuk tombol 1
        delay(300); // Debouncing delay
    } else if (digitalRead(BUTTON2_PIN) == LOW) {
        irsend.sendNEC(0xFF629D, 22);  // Ganti dengan kode yang sesuai untuk tombol 2
        delay(300); // Debouncing delay
    } else if (digitalRead(BUTTON3_PIN) == LOW && !button3Pressed) {
        button3Pressed = true; // Menandai tombol 3 telah ditekan
        irsend.sendNEC(0xFFE21D, 32);  // Ganti dengan kode yang sesuai untuk tombol 3
        delay(300); // Debouncing delay
    } else if (digitalRead(BUTTON3_PIN) == HIGH && button3Pressed) {
        button3Pressed = false; // Menandai tombol 3 telah dilepas
    } else if (digitalRead(BUTTON4_PIN) == LOW) {
        irsend.sendNEC(0xFF22DD, 32);  // Ganti dengan kode yang sesuai untuk tombol 4
        delay(300); // Debouncing delay
    } else if (digitalRead(BUTTON5_PIN) == LOW && !button5Pressed) {
        button5Pressed = true; // Menandai tombol 5 telah ditekan
        irsend.sendNEC(0xFF02FD, 32);  // Ganti dengan kode yang sesuai untuk tombol 5
        delay(300); // Debouncing delay
    } else if (digitalRead(BUTTON5_PIN) == HIGH && button5Pressed) {
        button5Pressed = false; // Menandai tombol 5 telah dilepas
    } else if (digitalRead(BUTTON6_PIN) == LOW) {
        irsend.sendNEC(0xFFC23D, 32);  // Ganti dengan kode yang sesuai untuk tombol 6
        delay(300); // Debouncing delay
    }
}

is that correct?

I'm still confused when selecting the button so as not to send the wrong hex code

You can put even 60 buttons, but only four can be used

Do you understand that you can't use these buttons as a two independent buttons - the reading of both buttons always will be the same.

use another controller with the required number of pins

or if you really really need to do it with those 4 pins, you could set 4 buttons to trigger one pin each, and two buttons that trigger two pins when pressed.
like:
button1 pin1
button2 pin2
button3 pin3
button4 pin4
button 5 pin1and2
button6 pin3and4

so you have 6 logical inputs

thank you

with the same logic you can have your six buttons with only 3 pins, if extra free pin is desired...

ok thank you

What help do you want and for what?

Will adding a resistor to each button make a big difference?

resistor for what? pullup?

In order to use a two different buttons on a single pin - it doesn't help you

I suggested to do opposite :wink:

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