Skip to content

Instantly share code, notes, and snippets.

@eric-vader
Last active December 24, 2023 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric-vader/8c1791ebe49a78f47e52800191a644c8 to your computer and use it in GitHub Desktop.
Save eric-vader/8c1791ebe49a78f47e52800191a644c8 to your computer and use it in GitHub Desktop.
#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