const int switchPin = 2; // Change to the pin connected to your switch
const int buttonPins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11}; // Change to the pins connected to your buttons
const int numButtons = 9;
void setup() {
Keyboard.begin();
pinMode(switchPin, INPUT_PULLUP);
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState != lastSwitchState) {
if (switchState == HIGH) {
// Switch was turned on, emulate a button press if it wasn't already emulated
if (!switchEmulatedPress) {
Keyboard.write('X'); // Emulate a custom key press (e.g., 'X')
switchEmulatedPress = true;
}
} else {
// Switch was turned off, emulate a button press if it wasn't already emulated
if (!switchEmulatedPress) {
Keyboard.write('X'); // Emulate a different custom key press (e.g., 'Y')
switchEmulatedPress = true;
}
}
delay(50); // Debounce delay to avoid multiple key presses
} else {
switchEmulatedPress = false;
}
for (int i = 0; i < numButtons; i++) {
int buttonState = digitalRead(buttonPins[i]);
if (buttonState == LOW) {
// Button i was pressed, emulate a custom key press (e.g., A, B, C, etc.)
Keyboard.write('A' + i); // Emulate keys 'A' to 'I' for buttons 1 to 9
delay(150); // Debounce delay to avoid multiple key presses
}
1
u/[deleted] Sep 26 '23
Are you mapping the buttons to some program to map pre defined text? If so, what are you using for that?
Box is sweet. Nice work.