Hii,
Fairly new to coding + working with an Arduino for the first time.
Using a Pro Micro I wanted to map each button to a letter on the keyboard, and so far so good!
The problem is I'd like to have the fourth button write 'E' instead of 'D' as long as button one ('A') was the last pressed button. Problematic loop below:
else if (digitalRead(6) == 0)
{
if (int lastButtonPressed = 3)
{
Keyboard.write('E');
}
else
{
Keyboard.write('D');
}
int lastButtonPressed = 6;
Serial.println(lastButtonPressed);
delay(200);
}
And here's the full code for context:
// key combonations
#include <Keyboard.h>
int lastButtonPressed = -1;
void setup() {
pinMode(3, INPUT_PULLUP); // usual button setup
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
Serial.begin(9600); // serial debug
}
void loop() {
Keyboard.begin();
if (digitalRead(3) == 0)
{
Keyboard.write('A');
int lastButtonPressed = 3;
Serial.println(lastButtonPressed);
delay(200);
}
else if (digitalRead(4) == 0)
{
Keyboard.write('B');
int lastButtonPressed = 4;
Serial.println(lastButtonPressed);
delay(200);
}
else if (digitalRead(5) == 0)
{
Keyboard.write('C');
int lastButtonPressed = 5;
Serial.println(lastButtonPressed);
delay(200);
}
else if (digitalRead(6) == 0)
{
if (int lastButtonPressed = 3)
{
Keyboard.write('E');
}
else
{
Keyboard.write('D');
}
int lastButtonPressed = 6;
Serial.println(lastButtonPressed);
delay(200);
}
Keyboard.end();
}
My mistake is probably very simple but I thought it couldn't hurt to ask. Thanks (^ω^)
