Weird Arduino Code Problem I'm currently getting started with Arduino, so I do not have very much knowledge.
In this project I have a receiver and a transmitter with 2 buttons.
So, I'd like to switch something to on, when I press the A button. If A is pressed longer I'd like something else to happen.
Same thing goes on with the B button, but for some reasons, when I long press A, then B gets triggered and I have no clue why...

Btw. this code is not purely made by me, but copied and edited for my use.
If anyone could help me I'd be very happy :)

code:

//ButtonAEvents

long prevA = 0;
long prevB = 0;
int buttonStateA = 0; // 0 = not pressed   --- 1 = long pressed --- 2 short pressed
int buttonStateB = 0; // 0 = not pressed   --- 1 = long pressed --- 2 short pressed
int ButtonAPin = 2;
int ButtonBPin = 3;
int DURATION_A_IN_MILLIS = 1000;
int DURATION_B_IN_MILLIS = 1000;

//ONE TIME SETUP

void setup()
{
    pinMode(ButtonAPin, INPUT);
    pinMode(ButtonBPin, INPUT);
    Serial.begin(9600);
}

//LOOP BEGIN

void loop()
{

    //BUTTON A CHECK
    buttonStateA = 0;
    if (digitalRead(ButtonAPin)) {
        prevA = millis();
        buttonStateA = 1;
        while ((millis() - prevA) &lt;= DURATION_A_IN_MILLIS) {
            if (!(digitalRead(ButtonAPin))) {
                buttonStateA = 2;
                break;
            }
        }
    }

    if (!buttonStateA) {
        // Nothin pressed
    }
    else if (buttonStateA == 1) {
        //LONG PRESS

        Serial.println("LongpressA");
        digitalWrite(A1, HIGH);
        delay(100);
    }
    else if (buttonStateA == 2) {
        //SHORT PRESS
        digitalWrite(A1, HIGH);
        Serial.println("ShortpressA");
        delay(100);
    }

    //BUTTON B CHECK
    buttonStateB = 0;
    if (digitalRead(ButtonBPin)) {
        prevB = millis();
        buttonStateB = 1;
        while ((millis() - prevB) &lt;= DURATION_B_IN_MILLIS) {
            if (!(digitalRead(ButtonBPin))) {
                buttonStateB = 2;
                break;
            }
        }
    }

    if (!buttonStateB) {
        // Nothin pressed
    }
    else if (buttonStateB == 1) {
        //SHORT PRESS

        Serial.println("LongpressB");
        delay(100);
    }
    else if (buttonStateB == 2) {
        //LONG PRESS
        digitalWrite(A1, LOW);
        Serial.println("ShortpressB");
        delay(100);
    }
}
Not sure if this is just an academic exercise on your part to learn (which is totally cool), but if you're just trying to move forward and get something working you may consider one of the many excellent button libraries out there for Arduino.

I recently used a library called ButtonKing that allowed me to do some very sophisticated menu interactions on a MKR1010 with a display and single button interface.  There are several other libraries out there as well that take care of debouncing, long clicks, double clicks, etc.