Last active
January 30, 2017 21:20
-
-
Save angelaperrone/ebd88ab1b531d34d8c9da156d84562dd 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
//step 1: add url for board | |
//Step 2: go to Board manager find and set board | |
//step 2: include keyboard library | |
//step 3: code! Reference - Tom Igoe - https://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl | |
//https://learn.adafruit.com/adafruit-feather-m0-adalogger/setup | |
//https://learn.adafruit.com/adafruit-feather-m0-adalogger/adapting-sketches-to-m0 | |
//https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/analog-in-with-an-arduino/ | |
//https://www.arduino.cc/en/Reference/KeyboardPress | |
//https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/digital-input-and-output-with-an-arduino/ | |
//----------CODE--------- | |
#include <Keyboard.h> | |
const int upButton = 13; | |
const int downButton = 12; | |
const int leftButton = 11; | |
const int rightButton = 10; | |
const int reloadButton = 9; | |
const int enterButton = 6; | |
const int ledPin = 5; | |
//int potMove; | |
int up; | |
int down; | |
int left; | |
int right; | |
int reload; | |
int enter; | |
int led; | |
void setup() { | |
Serial.begin (9600); //set up serial baud rate | |
pinMode(upButton, INPUT_PULLUP); | |
pinMode(downButton, INPUT_PULLUP); | |
pinMode(leftButton, INPUT_PULLUP); | |
pinMode(rightButton, INPUT_PULLUP); | |
pinMode(reloadButton, INPUT_PULLUP); | |
pinMode(enterButton, INPUT_PULLUP); | |
pinMode(ledPin, OUTPUT); | |
Keyboard.begin(); | |
} | |
// | |
void loop() { | |
up = digitalRead(upButton); | |
down = digitalRead(downButton); | |
left = digitalRead(leftButton); | |
right = digitalRead(rightButton); | |
reload = digitalRead(reloadButton); | |
enter = digitalRead(enterButton); | |
//potMove = analogRead(A2); | |
// led = digitalRead(ledPin); | |
//use buttons and pot to control keyboard | |
// Serial.println(potMove); | |
if (up == LOW) { | |
Keyboard.press('w'); | |
Serial.println("UP"); | |
delay(10); | |
Keyboard.release('w'); | |
} | |
if (down == LOW) { | |
Keyboard.press('s'); | |
Serial.println("DOWN"); | |
delay(10); | |
Keyboard.release('s'); | |
} | |
if (right == LOW) { | |
Keyboard.press ('d'); | |
Serial.println("RIGHT_"); | |
delay(10); | |
Keyboard.release('d'); | |
} | |
if (left == LOW) { | |
Keyboard.press('a'); | |
Serial.println("LEFT_"); | |
delay(10); | |
Keyboard.release('a'); | |
} | |
if (reload == LOW) { | |
Keyboard.press(135); | |
Keyboard.press('r'); | |
delay(50); | |
Keyboard.releaseAll(); | |
digitalWrite(ledPin, HIGH); | |
delay(1000); | |
Serial.println("RELOAD"); | |
digitalWrite(ledPin, LOW); | |
} | |
if (enter == LOW) { | |
Keyboard.write(176); | |
digitalWrite(ledPin, HIGH); | |
delay(1000); | |
digitalWrite(ledPin, LOW); | |
Serial.println("ENTER"); | |
} | |
// delay(1); | |
// if (up == LOW) { | |
// Serial.println("UP"); | |
// } | |
// | |
// if (down == LOW) { | |
// Serial.println("DOWN"); | |
// } | |
// | |
// if (left == LOW) { | |
// Serial.println("LEFT"); | |
// } | |
// | |
// if (right == LOW) { | |
// Serial.println("RIGHT"); | |
// } | |
// if (potMove <= 127) { | |
// Serial.println("RIGHT"); | |
// } | |
//if (potMove >= 823) { | |
// Serial.println("LEFT"); | |
// } | |
//delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment