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

Thread: Teensy push button

  1. #1
    Junior Member
    Join Date
    Sep 2017

    Teensy push button

    Hello I would like some help with some code
    I have teensy 2.0 and I want to push a button and then it print a letter on the screen so I would short pin 0 with gnd and the print a letter (a) for example
    But I want to print it once and have no mechanical chatter ?

    So far I have this but it just when pressed just prints a string of numbers

    /* Buttons to USB Keyboard

    You must select Keyboard from the "Tools > USB Type" menu

    #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 button0 = Bounce(0, 10);
    Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time
    Bounce button2 = Bounce(2, 10); // which is appropriate for
    Bounce button3 = Bounce(3, 10); // most mechanical pushbuttons
    Bounce button4 = Bounce(4, 10);

    void setup() {
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(4, INPUT_PULLUP);
    void SendKey(int key) {


    Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);



    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.

    // Check each button for "falling" edge.
    // Type a message on the Keyboard when each button presses
    // falling = high (not pressed - voltage from pullup resistor)
    // to low (pressed - button connects pin to ground)
    if (button0.fallingEdge()) {
    if (button1.fallingEdge()) {
    if (button2.fallingEdge()) {
    if (button3.fallingEdge()) {
    if (button4.fallingEdge()) {

  2. #2
    Junior Member
    Join Date
    Jan 2017
    When you say that it just "prints a string of numbers"... Do you mean it prints several characters in a row due to button chatter or does it continue sending characters constantly?
    If it is chatter, take a look at the Bounce2 library and you may want to change library to LOCKOUT method using #define BOUNCE_LOCK_OUT. Check out comments in library. or google that to see the difference in dampening methods that library uses to prevent chatter.
    If it is constantly sending, it may be due to you not having a "Repeat delay timer" programmed in as a way to prevent it from continually sending characters. I guess you were relying on the button.fallingEdge() function to do this. I haven't looked at the Bounce library but that may or may not repeat for some reason.. It shouldn't repeat but just take a look at code in that library to check.

Tags for this Thread

Posting Permissions

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