Hello there
Arduino Pro Micro
Arduino IDE 2.2.1
Windows 10
I have six toggle switches, each of which are supposed to only sent a "keystroke" (so sw1 -> "1", sw2 -> "2"... and so on) when toggled either on or off.
To save Pins I want to combine the switch's inputs if possible (A3). The outputs are right now connected to Pin 2 to 7.
The sinner I am, I decided to use ChatGPT but oh god what a mess. Maybe I used the wrong prompts but I got code which just didnt work. I will however attach the code I have been using prior to this where i only used one button which worked flawlessly.
Thanks for any help, ideas or maybe even solutions!
The Code:
#include "Keyboard.h"
const int switchPin = A3;
void setup() {
pinMode(switchPin, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
static int previousState = HIGH;
int currentState = digitalRead(switchPin);
if (currentState != previousState) {
delay(10);
if (currentState == LOW) {
Keyboard.write('7');
} else {
Keyboard.write('7');
}
delay(10);
previousState = currentState;
}
}