Close

Code for the Claw

A project log for MineCraft Sidecar Keypad

A Minecraft keypad setup with various macros

toulonToulon 10/03/2014 at 23:420 Comments
Teensy Claw Rev3 Sketch
Below is the code for the Claw Rebuild project.
-------------------------Code Start------------------------ #include <Bounce.h>

// Debounce button creation
Bounce keybutton0 = Bounce(0, 40);
Bounce keybutton1 = Bounce(1, 40);
Bounce keybutton2 = Bounce(2, 40);
Bounce keybutton3 = Bounce(3, 40);
Bounce keybutton4 = Bounce(4, 40);
Bounce keybutton5 = Bounce(5, 40);
Bounce keybutton6 = Bounce(6, 40);
Bounce keybutton7 = Bounce(7, 40);
Bounce keybutton8 = Bounce(8, 40);
Bounce keybutton9 = Bounce(9, 60);
Bounce keybutton10 = Bounce(10, 60);
Bounce keybutton21 = Bounce(10, 40);
byte left = 0;
byte middle = 0;
byte right = 0;
byte shift = 0;
byte clicked = 0;
void setup() {

// put your setup code here, to run once:
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(21, INPUT_PULLUP);
}

void loop() {
int mode = 0;

mode = digitalRead(11);

if (mode == HIGH) {
// turn LED on:
KeyPad();
}
else {
JoyMode();
}
}

void KeyPad() {
// put your main code here, to run repeatedly:
keybutton0.update();
keybutton1.update();
keybutton2.update();
keybutton3.update();
keybutton4.update();
keybutton5.update();
keybutton6.update();
keybutton7.update();
keybutton8.update();
keybutton9.update();
keybutton10.update();
byte anyChange = 0;

// Single press buttons
// Space Button
if (keybutton3.fallingEdge()) {
Keyboard.set_key5(KEY_SPACE);
Keyboard.send_now();
}
if (keybutton3.risingEdge()) {
Keyboard.set_key5(0);
Keyboard.send_now();
}
// F button
if (keybutton2.fallingEdge()) {
Keyboard.set_key6(KEY_F);
Keyboard.send_now();
delay(2);
Keyboard.set_key6(0);
Keyboard.send_now();
}
// Auto Sprint key
if (keybutton1.fallingEdge()) {
Keyboard.set_key6(KEY_W);
Keyboard.send_now();
delay(2);
Keyboard.set_key6(0);
Keyboard.send_now();
delay(2);
Keyboard.set_key6(KEY_W);
Keyboard.send_now();
}
if (keybutton1.risingEdge()) {
Keyboard.set_key6(0);
Keyboard.send_now();
}

// E button
if (keybutton4.fallingEdge()) {
Keyboard.set_key6(KEY_E);
Keyboard.send_now();
delay(2);
Keyboard.set_key6(0);
Keyboard.send_now();
}
// D button
if (keybutton5.fallingEdge()) {
Keyboard.set_key4(KEY_D);
Keyboard.send_now();
}
if (keybutton5.risingEdge()) {
Keyboard.set_key4(0);
Keyboard.send_now();
}
// W button
if (keybutton6.fallingEdge()) {
Keyboard.set_key1(KEY_W);
Keyboard.send_now();
}
if (keybutton6.risingEdge()) {
Keyboard.set_key1(0);
Keyboard.send_now();
}
// S button
if (keybutton7.fallingEdge()) {
Keyboard.set_key2(KEY_S);
Keyboard.send_now();
}
if (keybutton7.risingEdge()) {
Keyboard.set_key2(0);
Keyboard.send_now();
}
// Q button
if (keybutton8.fallingEdge()) {
Keyboard.set_key6(KEY_Q);
Keyboard.send_now();
delay(2);
Keyboard.set_key6(0);
Keyboard.send_now();
}
// A Button
if (keybutton9.fallingEdge()) {
Keyboard.set_key3(KEY_A);
Keyboard.send_now();
}
if (keybutton9.risingEdge()) {
Keyboard.set_key3(0);
Keyboard.send_now();
}
// Shift Toggle button
if (keybutton10.fallingEdge()) {
if (shift == 0) {
Keyboard.set_modifier(MODIFIERKEY_SHIFT);
Keyboard.send_now();
shift = 1;
}
else {
Keyboard.set_modifier(0);
Keyboard.send_now();
shift = 0;
}

}

// Mouse button left
if (keybutton0.fallingEdge()) {
if (clicked == 0) {
left = 1;
anyChange = 1;
clicked = 1;
}
else {
clicked = 0;
left = 0;
anyChange = 1;
}
}



if (anyChange) {
Mouse.set_buttons(left, middle, right);
}

}
void JoyMode(){
// put your main code here, to run repeatedly:
keybutton0.update();
keybutton1.update();
keybutton2.update();
keybutton3.update();
keybutton4.update();
keybutton5.update();
keybutton6.update();
keybutton7.update();
keybutton8.update();
keybutton9.update();
keybutton10.update();
keybutton21.update();

//Joystick buttons Falling
if (keybutton0.fallingEdge()) {
Joystick.button(1, 1);
}
if (keybutton1.fallingEdge()) {
Joystick.button(2, 1);
}
if (keybutton2.fallingEdge()) {
Joystick.button(3, 1);
}
if (keybutton3.fallingEdge()) {
Joystick.button(4, 1);
}
if (keybutton4.fallingEdge()) {
Joystick.button(5, 1);
}
if (keybutton5.fallingEdge()) {
Joystick.button(6, 1);
}
if (keybutton6.fallingEdge()) {
Joystick.button(7, 1);
}
if (keybutton7.fallingEdge()) {
Joystick.button(8, 1);
}
if (keybutton8.fallingEdge()) {
Joystick.button(9, 1);
}
if (keybutton9.fallingEdge()) {
Joystick.button(10, 1);
}
if (keybutton10.fallingEdge()) {
Joystick.button(11, 1);
}
//Joystick buttons Rising
if (keybutton0.risingEdge()) {
Joystick.button(1, 0);
}
if (keybutton1.risingEdge()) {
Joystick.button(2, 0);
}
if (keybutton2.risingEdge()) {
Joystick.button(3, 0);
}
if (keybutton3.risingEdge()) {
Joystick.button(4, 0);
}
if (keybutton4.risingEdge()) {
Joystick.button(5, 0);
}
if (keybutton5.risingEdge()) {
Joystick.button(6, 0);
}
if (keybutton6.risingEdge()) {
Joystick.button(7, 0);
}
if (keybutton7.risingEdge()) {
Joystick.button(8, 0);
}
if (keybutton8.risingEdge()) {
Joystick.button(9, 0);
}
if (keybutton9.risingEdge()) {
Joystick.button(10, 0);
}
if (keybutton10.risingEdge()) {
Joystick.button(11, 0);
}

}
-------------------------Code End-------------------------

Discussions