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);
Keyboard.send_now();
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
Keyboard.set_key1(key);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
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.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
// 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()) {
SendKey(KEY_F1);
}
if (button1.fallingEdge()) {
SendKey(KEY_F2);
}
if (button2.fallingEdge()) {
SendKey(KEY_F3);
}
if (button3.fallingEdge()) {
SendKey(KEY_F4);
}
if (button4.fallingEdge()) {
SendKey(KEY_F5);
}
}
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);
Keyboard.send_now();
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.send_now();
Keyboard.set_key1(key);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
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.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
// 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()) {
SendKey(KEY_F1);
}
if (button1.fallingEdge()) {
SendKey(KEY_F2);
}
if (button2.fallingEdge()) {
SendKey(KEY_F3);
}
if (button3.fallingEdge()) {
SendKey(KEY_F4);
}
if (button4.fallingEdge()) {
SendKey(KEY_F5);
}
}