SHARE
TWEET
Switch Tester Teensy2.0 Code
a guest
Mar 7th, 2015
435
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- /* Buttons to USB Keyboard Example
- You must select Keyboard from the "Tools > USB Type" menu
- This example code is in the public domain.
- */
- #include <Bounce.h>
- // Create Bounce objects for each button. The Bounce object
- // automatically deals with contact chatter or "bounce", and
- // it makes detecting changes very simple.
- Bounce button13 = Bounce(13, 10);
- Bounce button14 = Bounce(14, 10); // 10 = 10 ms debounce time
- Bounce button15 = Bounce(15, 10); // which is appropriate for
- Bounce button16 = Bounce(16, 10); // most mechanical pushbuttons
- Bounce button17 = Bounce(17, 10);
- Bounce button18 = Bounce(18, 10); //change 13-18 to your pins #s
- void setup() {
- // Configure the pins for input mode with pullup resistors.
- // The pushbuttons connect from each pin to ground. When
- // the button is pressed, the pin reads LOW because the button
- // shorts it to ground. When released, the pin reads HIGH
- // because the pullup resistor connects to +5 volts inside
- // the chip. LOW for "on", and HIGH for "off" may seem
- // backwards, but using the on-chip pullup resistors is very
- // convenient. The scheme is called "active low", and it's
- // very commonly used in electronics... so much that the chip
- // has built-in pullup resistors!
- pinMode(13, INPUT_PULLUP);
- pinMode(14, INPUT_PULLUP);
- pinMode(15, INPUT_PULLUP);
- pinMode(16, INPUT_PULLUP);
- pinMode(17, INPUT_PULLUP);
- pinMode(18, INPUT_PULLUP);
- }
- void loop() {
- // Update all the buttons. There should not be any long
- // delays in loop(), so this runs repetitively at a rate
- // faster than the buttons could be pressed and released.
- button13.update();
- button14.update();
- button15.update();
- button16.update();
- button17.update();
- button18.update();
- // Check each button for "falling" edge.
- // Type a message on the Keyboard when each button presses
- // Update the Joystick buttons only upon changes.
- // falling = high (not pressed - voltage from pullup resistor)
- // to low (pressed - button connects pin to ground)
- //tldr=what action do you want to execute on a key press
- if (button13.fallingEdge()) { //green switch
- Keyboard.set_modifier(0);
- Keyboard.set_key1(0);
- for(int n=1; n<5; n++){
- Keyboard.print("Reason ");
- Keyboard.println(n);
- Keyboard.send_now();
- Keyboard.set_key1(KEY_TAB);
- Keyboard.send_now();
- Keyboard.set_key1(0);
- Keyboard.send_now();
- delay(100);
- }
- }
- if (button14.fallingEdge()) { //blue switch
- Keyboard.set_modifier(MODIFIERKEY_CTRL);
- Keyboard.set_key2(KEY_A);
- Keyboard.send_now();
- delay(50);
- Keyboard.set_modifier(0);
- Keyboard.set_key2(0);
- Keyboard.send_now();
- }
- if (button15.fallingEdge()) { //clear switch
- Keyboard.set_modifier(MODIFIERKEY_CTRL);
- Keyboard.set_key3(KEY_C);
- Keyboard.send_now();
- delay(50);
- Keyboard.set_modifier(0);
- Keyboard.set_key3(0);
- Keyboard.send_now();
- }
- if (button16.fallingEdge()) { //brown switch
- Keyboard.set_modifier(MODIFIERKEY_CTRL);
- Keyboard.set_key4(KEY_V);
- Keyboard.send_now();
- delay(50);
- Keyboard.set_modifier(0);
- Keyboard.set_key4(0);
- Keyboard.send_now();
- }
- if (button17.fallingEdge()) { //black switch
- Keyboard.set_modifier(MODIFIERKEY_ALT);
- Keyboard.send_now();
- Keyboard.set_key5(KEY_TAB);
- Keyboard.send_now();
- delay(50);
- Keyboard.set_key5(0);
- Keyboard.send_now();
- }
- //risingEdge=what action do you want to execute on a key release
- if (button17.risingEdge()){
- Keyboard.set_modifier(0);
- Keyboard.send_now();
- }
- if (button18.fallingEdge()) { //red switch
- Keyboard.set_key6(KEY_TAB);
- Keyboard.send_now();
- delay(50);
- Keyboard.set_key6(0);
- Keyboard.send_now();
- }
- }
RAW Paste Data
