Hi guys,
I'm new to all this, but I've soldered 3 cherry switches to my Trinket via pin # 0,1,2
I'm following Adafruit's tutorial example for the code, with the additional of a keyswitch on pin #1.
The code is below. Pin 2 (Enter), and pin 0 (Backspace) works fine. Pin 1 (A) works as well, except that it keeps typing "A"s until I pull the plug on the Trinket.
Can anyone please point me in the right direction on what to change, so that the pin #1 switch (A), doesn't continuously repeat itself?
Thank you in advance!
#include <TrinketKeyboard.h>
#define PIN_BUTTON_ENTER 2
#define PIN_BUTTON_BACKSPACE 0
#define PIN_BUTTON_A 1
void setup()
{
// button pins as inputs
pinMode(PIN_BUTTON_ENTER, INPUT);
pinMode(PIN_BUTTON_BACKSPACE, INPUT);
pinMode(PIN_BUTTON_A, INPUT);
// setting input pins to high means turning on internal pull-up resistors
digitalWrite(PIN_BUTTON_ENTER, HIGH);
digitalWrite(PIN_BUTTON_BACKSPACE, HIGH);
digitalWrite(PIN_BUTTON_A, HIGH);
// remember, the buttons are active-low, they read LOW when they are not pressed
// start USB stuff
TrinketKeyboard.begin();
}
void loop()
{
TrinketKeyboard.poll();
// the poll function must be called at least once every 10 ms
// or cause a keystroke
// if it is not, then the computer may think that the device
// has stopped working, and give errors
if (digitalRead(PIN_BUTTON_ENTER) == LOW)
{
TrinketKeyboard.pressKey(0, KEYCODE_ENTER);
// this should press end
TrinketKeyboard.pressKey(0, 0);
// this releases the key
delay(500);
}
if (digitalRead(PIN_BUTTON_BACKSPACE) == LOW)
{
TrinketKeyboard.pressKey(0, KEYCODE_BACKSPACE);
// this should press home using the led
TrinketKeyboard.pressKey(0, 0);
// this releases the key
delay(500);
}
if (digitalRead(PIN_BUTTON_A) == LOW)
{
TrinketKeyboard.pressKey(0, KEYCODE_A);
// this should press insert
TrinketKeyboard.pressKey(0, 0);
// this releases the key
delay(500);
}
}