Skip to content

Instantly share code, notes, and snippets.

@Tiriree
Created February 22, 2017 04:53
Show Gist options
  • Save Tiriree/d9e4bb31def260c5f0bedd0f5ffe8529 to your computer and use it in GitHub Desktop.
Save Tiriree/d9e4bb31def260c5f0bedd0f5ffe8529 to your computer and use it in GitHub Desktop.
/*
KeyboardControl for music controller
tangible workshop's assignments - wed
using https://www.arduino.cc/en/Reference/KeyboardModifiers
https://www.arduino.cc/en/Reference/ASCIIchart
inspired by Tom Igoe
and help from Regina and Sebastian <3
*/
#include "Keyboard.h"
// set pin numbers for the six buttons:
char first = 51;
char second = 53;
char third = 50;
char fourth = 49;
char fifth = 54;
char sixth = 52;
//check to see if the bottom release on time
bool firstUp = LOW;
bool secondUp = LOW;
bool thirdUp = LOW;
bool fourthUp = LOW;
bool fifthUp = LOW;
bool sixthUp = LOW;
void setup() { // initialize the buttons' inputs:
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
// use the pushbuttons to control the keyboard:
if (digitalRead(2) == HIGH) {
if (firstUp == LOW) {
//press
Keyboard.press(first);
firstUp = HIGH;
delay (50);
}
} else {
if (firstUp == HIGH) {
//releasing
Keyboard.releaseAll();
firstUp = LOW;
delay (50);
}
}
if (digitalRead(3) == HIGH) {
if (secondUp == LOW) {
//press
Keyboard.press(second);
secondUp = HIGH;
delay (50);
}
} else {
if (secondUp == HIGH) {
//releasing
Keyboard.releaseAll();
secondUp = LOW;
delay (50);
}
}
if (digitalRead(4) == HIGH) {
if (thirdUp == LOW) {
//press
Keyboard.press(third);
thirdUp = HIGH;
delay (50);
}
} else {
if (thirdUp == HIGH) {
//releasing
Keyboard.releaseAll();
thirdUp = LOW;
delay (50);
}
}
if (digitalRead(5) == HIGH) {
if (fourthUp == LOW) {
//press
Keyboard.press(fourth);
fourthUp = HIGH;
delay (50);
}
} else {
if (fourthUp == HIGH) {
//releasing
Keyboard.releaseAll();
fourthUp = LOW;
delay (50);
}
}
if (digitalRead(6) == HIGH) {
if (fifthUp == LOW) {
//press
Keyboard.press(fifth);
fifthUp = HIGH;
delay (50);
}
} else {
if (fifthUp == HIGH) {
//releasing
Keyboard.releaseAll();
fifthUp = LOW;
delay (50);
}
}
if (digitalRead(7) == HIGH) {
if (sixthUp == LOW) {
//press
Keyboard.press(sixth);
sixthUp = HIGH;
delay (50);
}
} else {
if (sixthUp == HIGH) {
//releasing
Keyboard.releaseAll();
sixthUp = LOW;
delay (50);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment