New to Teensy

Status
Not open for further replies.
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
 
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.
 
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
 
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:
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?
 
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
 
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
 
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
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top