Last active
December 24, 2023 15:03
-
-
Save eric-vader/8c1791ebe49a78f47e52800191a644c8 to your computer and use it in GitHub Desktop.
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 <Keyboard.h> | |
int outSound = 2; | |
int outFairyRight = 3; | |
int outFairyLeft = 4; | |
int inWire = 12; | |
int powerHigh = 22; | |
int outLED = 13; | |
int inButton = 51; | |
int previousButtonState = HIGH; | |
int pressKey = KEY_RETURN; | |
int delayBetweenKeys = 50; | |
int buttonState = LOW; | |
void setup() | |
{ | |
pinMode(outLED, OUTPUT); | |
pinMode(outSound, OUTPUT); | |
pinMode(outFairyRight, OUTPUT); | |
pinMode(outFairyLeft, OUTPUT); | |
pinMode(inWire, INPUT); | |
pinMode(powerHigh, OUTPUT); | |
digitalWrite(powerHigh, HIGH); | |
pinMode(inButton, INPUT); | |
} | |
void loop() | |
{ | |
if (!digitalRead(inWire)) | |
{ | |
// When wire is touched | |
digitalWrite(outSound, HIGH); | |
digitalWrite(outFairyRight, HIGH); | |
digitalWrite(outFairyLeft, HIGH); | |
} | |
else | |
{ | |
digitalWrite(outSound, LOW); | |
digitalWrite(outFairyRight, LOW); | |
digitalWrite(outFairyLeft, LOW); | |
} | |
buttonState = digitalRead(inButton); | |
// replaces button press with UP arrow | |
if (buttonState == LOW && previousButtonState == HIGH) | |
{ | |
// and it's currently pressed: | |
Keyboard.press(pressKey); | |
digitalWrite(outLED, HIGH); | |
delay(delayBetweenKeys); | |
} | |
if (buttonState == HIGH && previousButtonState == LOW) | |
{ | |
// and it's currently released: | |
Keyboard.release(pressKey); | |
digitalWrite(outLED, LOW); | |
delay(delayBetweenKeys); | |
} | |
previousButtonState = buttonState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment