New Arduino micro user here and I would like some guidance.
My end game goal would be to create a switch box to use in a video game (flight sim style)
Obviously I'm not going to start of attempting a multiple switch layout right away as I need to learn some basics.
I've gone through all of the 'intro tutorials' and am now looking for next steps. I have three different switches I've purchased and would like to start learning how to make them work, but most guides and articles I find are pointing towards matrixes and multi switch type layouts, or macro pads using cherry switches which I'm not ready for yet.
Does anyone have any links to guides and tutorials for maybe setting up one or two switches? I'm having a hard time finding relevant documentation and feeling a bit inundated with the amount of information available.
For reference, the types of switches I have are:
On/off/on
On/off
Mini 8 rotary
Thank you guys so much in advance. I know that working with noobies with delusions of grandeur can be a bit frustrating.
Just to attempt to get an idea of what I'm doing, I'm using 3 buttons on a breadboard. My pin layout looks something like this:
(sorry for the terrible diagramming here)
The code I've ripped and attempted to retrofit looks like this:
/*
DIY Arcade HotKey
Modififed version of the KeyboardReprogram firmware -
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
Allows you to set different buttons to be hotkeys for the computer.
*/
#include <Keyboard.h>
// use this option for OSX.
// Comment it out if using Windows or Linux:
//char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux.
// leave commented out if using OSX:
char ctrlKey = KEY_LEFT_CTRL;
char altKey = KEY_LEFT_ALT;
int buttonNum[3] = {2, 3, 4};
int buttSelect = 0;
int buttFlag = 0;
void setup() {
Serial.begin(115200);
for (int x = 0; x < 3; x++) {
pinMode(buttonNum[x], INPUT_PULLUP);
attachInterrupt(buttonNum[x], buttPressed, LOW);
}
Keyboard.begin();
}
void loop() {
while (buttFlag == 0) {
delay(10);
}
Serial.print("Button ");
Serial.print(buttSelect);
Serial.println(" pressed.");
switch (buttSelect) {
case 2:
Command2();
break;
case 3:
Command3();
break;
case 4:
Command4();
break;
default:
break;
}
int pressed = digitalRead(buttSelect);
while (pressed == 0) {
pressed = digitalRead(buttSelect);
}
buttFlag = 0;
}
void buttPressed() {
buttFlag = 1;
for (int x = 0; x < 3; x++) {
int butt = digitalRead(x);
if (butt == LOW) {
buttSelect = x;
break;
}
}
}
//Add your own Hot-Key combinations below.
//Upload to Arduino
void Command2() {
Serial.println("Pressing CTRL+U");
Keyboard.press(ctrlKey);
Keyboard.press('u');
delay(100);
Keyboard.releaseAll();
delay(500);
}
void Command3() {
Serial.println("Pressing CTRL+ALT+N");
Keyboard.press(ctrlKey);
Keyboard.press(altKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
delay(500);
}
void Command4() {
Keyboard.println("HelloWorld");
}
Unfortunately this is not yielding any results in my serial monitor. Any ideas where I may be going wrong?