Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: New to Teensy

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    5

    New to Teensy

    Hey im looking to make a controller for my pc. I need it to have 4 keys w,a,s,d which im thinking about getting CHERRY MX Silent Red switches but im not sure how i would connect this up with the teensy and on that note which teensy would be best?

    Thanks

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Canada
    Posts
    837
    any of the teensy 3* can send usb keystrokes to your pc

  3. #3
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    395
    Are you looking to just buy 4 of the Cherry switches and build your own enclosure?

    If so, you'd just connect those 4 switches to 4 inputs pins on the Teensy. There's plenty of examples on how to wire and read a switch, like here: https://www.arduino.cc/en/Tutorial/Button

    Once you can read the switches you'll add some more code to echo that to the computer via USB, as tonton81 describes above. Even the least expensive (Teensy LC) will be able to handle this.

  4. #4
    Junior Member
    Join Date
    Nov 2017
    Posts
    5
    Quote Originally Posted by potatotron View Post
    Are you looking to just buy 4 of the Cherry switches and build your own enclosure?

    If so, you'd just connect those 4 switches to 4 inputs pins on the Teensy. There's plenty of examples on how to wire and read a switch, like here: https://www.arduino.cc/en/Tutorial/Button

    Once you can read the switches you'll add some more code to echo that to the computer via USB, as tonton81 describes above. Even the least expensive (Teensy LC) will be able to handle this.
    I already have a enclosure, its called stinkyboard (http://www.stinkyboard.com/) but all the parts inside are dead so was thinking i could replace it all with Teensy and Cherry switches.
    Is it as simple as just 1 wire from switch to teensy then? Just get it in the right pin? Then code it?
    I brought a 3.2 Teensy, solderless breadboard with wires and the switches is this all i need to buy as already have a soldering iron and that sort of stuff?
    Thanks again

  5. #5
    Senior Member
    Join Date
    Dec 2016
    Location
    Canada
    Posts
    837
    if the button is wired to ground, other side to teensy pin, yes, one pin. suggest you put a 220-330 ohm series resistor always to protect the pin.

    in your code its as simple as:

    Setting the pin to work with your button:
    pinMode(pin, INPUT_PULLUP);

    Then checking the state in your loop:
    if ( digitalReadFast(pin) == 0 ) {
    //button pushed, do something
    delay(10);
    }

    of course, since your planning to push and possibly hold the button, you'd have to adjust your code to compensate for it...

    while ( digitalReadFast(pin) == 0 ) {
    while ( digitalReadFast(pin) == 0 ); //wait here until you let go
    //button pushed, do something
    delay(10);
    }

    then theres always possibilities for long hold does something different than a quick press
    endless possibilities, but those interests deserve their own posts
    Last edited by tonton81; 12-01-2017 at 01:47 PM.

  6. #6
    Junior Member
    Join Date
    Nov 2017
    Posts
    5
    Quote Originally Posted by tonton81 View Post
    if the button is wired to ground, other side to teensy pin, yes, one pin. suggest you put a 220-330 ohm series resistor always to protect the pin.

    in your code its as simple as:

    Setting the pin to work with your button:
    pinMode(pin, INPUT_PULLUP);

    Then checking the state in your loop:
    if ( digitalReadFast(pin) == 0 ) {
    //button pushed, do something
    delay(10);
    }

    of course, since your planning to push and possibly hold the button, you'd have to adjust your code to compensate for it...

    while ( digitalReadFast(pin) == 0 ) {
    while ( digitalReadFast(pin) == 0 ); //wait here until you let go
    //button pushed, do something
    delay(10);
    }

    then theres always possibilities for long hold does something different than a quick press
    endless possibilities, but those interests deserve their own posts
    Is they a place i could order that 220-330 ohm series resistor in the uk?
    yeah i need to code to let me hold down the button till i let go could be a very long time so would that be easy to do?

  7. #7
    Senior Member
    Join Date
    Dec 2016
    Location
    Canada
    Posts
    837
    yeah, the example above is technically blocking and a delay safety to prevent bounce, just for simple demonstration and easy to understand.

    could make it more efficient and faster afterwards obviously, depending on how exactly you want it to operate, it can be coded to your needs

    any electronics shops should have resistors, theyre just a few pennies even at retail local shops

  8. #8
    Junior Member
    Join Date
    Nov 2017
    Posts
    5
    Yeah iv just found them
    i just want it to be like a keyboard, just w,a,s,d for gaming. So long w press and then say D at the sometime or just W. I hope im making sence

  9. #9
    Senior Member
    Join Date
    Dec 2016
    Location
    Canada
    Posts
    837
    yes, even both, three, or 4 at the same time is possible as well

    you could also simulate the keyboard method of after pressing and holding , it sends the keystroke initially, and after a few microseconds of still holding, it can constantly repeate the same keystroke, like an actual keyboard does

    or even custom make rapid fire keystrokes for games that use multi key sequencing

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,263
    After installing Teensyduino, in Arduino click File > Examples > Teensy > USB_Keyboard > Buttons for an example which should do most of what you want. Just edit the string it sends, maybe delete the parts which send on button release since you only wish the send on press, right?

    You could also edit the code to use Keyboard.press() and Keyboard.release() instead of Keyboard.print(), if you want actual timing control over when the PC sees the keys pressed and released. Details here:

    https://www.pjrc.com/teensy/td_keyboard.html

    Whatever you do, I recommend starting from that example which uses the Bounce library to read the buttons. Bounce automatically handles mechanical chatter, which will save you from a lot of frustration.

  11. #11
    Junior Member
    Join Date
    Nov 2017
    Posts
    5
    Ok this is sounding very good and i think i will be able to fix my foot board so i can game again.
    Paul i have no idea, im new to this and coding tbh. I just know before it was broke i could just hold W forever if needed and do D for a few seconds if needed then carry on with W, if this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •