Created
July 16, 2021 16:34
-
-
Save Crysknife007/69b2b13719187ee6784f3eafa5ca131a to your computer and use it in GitHub Desktop.
Digispark Press Space Bar with Arcade Button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DigiKeyboard.h" | |
// Define button pin | |
const int buttonPin = 2; | |
// Define button state | |
int buttonState = 0; | |
// Setup | |
void setup() { | |
// Set button to input | |
pinMode(buttonPin, INPUT_PULLUP); | |
} | |
// Main loop | |
void loop() { | |
// Read the button state | |
buttonState = digitalRead(buttonPin); | |
// If the button state is low | |
if ( buttonState == LOW ) { | |
// Send a spacebar key press | |
DigiKeyboard.sendKeyPress(44); | |
} | |
// Else clear the keys | |
else { | |
// Clear all the keys | |
DigiKeyboard.sendKeyStroke(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment