add digital IO controller inputs
This commit is contained in:
parent
424368716e
commit
760b306ddd
2 changed files with 39 additions and 8 deletions
|
@ -27,3 +27,11 @@ build_flags =
|
|||
-D PIXELPIN=4
|
||||
-D NUMPIXELS=600
|
||||
-D CHANNEL=1
|
||||
|
||||
-D PIN_IN1=14
|
||||
-D PIN_IN2=13
|
||||
-D PIN_IN3=12
|
||||
-D PIN_IN4=11
|
||||
|
||||
-D DEBOUNCETIME_WIRED=10
|
||||
|
||||
|
|
|
@ -28,21 +28,31 @@ Adafruit_NeoPixel statuspixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
|||
USBHIDKeyboard Keyboard;
|
||||
|
||||
#define NUM_CONTROLLERS 4
|
||||
#define NUM_CONTROLLERS_WIRED 4
|
||||
|
||||
uint32_t controllercolors[]={\
|
||||
statuspixel.Color(255, 0,0),\
|
||||
statuspixel.Color(0, 255,0),\
|
||||
statuspixel.Color(0,0, 255),\
|
||||
statuspixel.Color(255, 255,0)\
|
||||
statuspixel.Color(255, 0,255)\
|
||||
};
|
||||
|
||||
uint8_t keyassignments[NUM_CONTROLLERS][INPUT_SIZE];
|
||||
|
||||
uint8_t keyassignmentsWired[NUM_CONTROLLERS_WIRED];
|
||||
bool in_last_wired[NUM_CONTROLLERS_WIRED];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
|
||||
pinMode(PIN_IN1,INPUT_PULLUP);
|
||||
pinMode(PIN_IN2,INPUT_PULLUP);
|
||||
pinMode(PIN_IN3,INPUT_PULLUP);
|
||||
pinMode(PIN_IN4,INPUT_PULLUP);
|
||||
keyassignmentsWired[0]=HID_KEY_V;
|
||||
keyassignmentsWired[1]=HID_KEY_B;
|
||||
keyassignmentsWired[2]=HID_KEY_N;
|
||||
keyassignmentsWired[3]=HID_KEY_M;
|
||||
|
||||
keyassignments[0][KEY_LEFT]=HID_KEY_A;
|
||||
keyassignments[0][KEY_RIGHT]=HID_KEY_D;
|
||||
|
@ -71,7 +81,6 @@ void setup() {
|
|||
keyassignments[3][KEY_DOWN]=HID_KEY_ARROW_DOWN;
|
||||
keyassignments[3][KEY_A]=HID_KEY_CONTROL_LEFT;
|
||||
keyassignments[3][KEY_B]=HID_KEY_SHIFT_LEFT;
|
||||
|
||||
|
||||
initESPNOW();
|
||||
|
||||
|
@ -115,6 +124,24 @@ void setup() {
|
|||
void loop() {
|
||||
unsigned long loopmillis=millis();
|
||||
|
||||
bool in[NUM_CONTROLLERS_WIRED];
|
||||
in[0]=digitalRead(PIN_IN1);
|
||||
in[1]=digitalRead(PIN_IN2);
|
||||
in[2]=digitalRead(PIN_IN3);
|
||||
in[3]=digitalRead(PIN_IN4);
|
||||
static unsigned long last_in_time[NUM_CONTROLLERS_WIRED];
|
||||
|
||||
for (uint8_t i=0;i<NUM_CONTROLLERS_WIRED;i++) {
|
||||
if (in[i]!=in_last_wired[i] && loopmillis-last_in_time[i]>=DEBOUNCETIME_WIRED) { //changed?
|
||||
if (!in[i]) {
|
||||
Keyboard.pressRaw(keyassignmentsWired[i]);
|
||||
}else{
|
||||
Keyboard.releaseRaw(keyassignmentsWired[i]);
|
||||
}
|
||||
last_in_time[i]=millis();
|
||||
}
|
||||
in_last_wired[i]=in[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -132,10 +159,6 @@ void processCommand(struct_message espnowdata) { //espnow data from remote
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (espnowdata.action==PRESS){
|
||||
statuspixel.setPixelColor(0, controllercolors[espnowdata.id]); //change status led when packet arrives
|
||||
Keyboard.pressRaw(keyassignments[espnowdata.id][espnowdata.input]);
|
||||
|
|
Loading…
Add table
Reference in a new issue