Hello Guys,
I just received my teensy 2 and I'm super excited to experience with it! This is really cool stuff...
I have a small questions. I'm trying to use the T2 as a keyboard with two buttons. Every time a button is pressed, it triggers an action on the computer (I already have that part working through vb .net).
All I need now is two send a specific set of keys for each button pressed. That works well through the following code :
As you can see, I'm instructing to light a led for 1 second when a press is detected and I send a combination of keys to the computer.
Now, if the second button is pressed during that second, then nothing will happen.
Thus the question, is it possible to call an outside function for the led to light for one second, but in parallel continue the loop?
Thanks a lot for your help!
Cheers
I just received my teensy 2 and I'm super excited to experience with it! This is really cool stuff...
I have a small questions. I'm trying to use the T2 as a keyboard with two buttons. Every time a button is pressed, it triggers an action on the computer (I already have that part working through vb .net).
All I need now is two send a specific set of keys for each button pressed. That works well through the following code :
Code:
int ledPin1 = 11;
int ledPin2 = 11;
int buttonPin1 = 0;
int buttonPin2 = 1;
void setup() {
pinMode(ledPin1, OUTPUT); // LED
pinMode(ledPin2, OUTPUT); // LED
pinMode(buttonPin1, INPUT_PULLUP); // Pushbutton
pinMode(buttonPin2, INPUT_PULLUP); // Pushbutton
}
void loop()
{
if (digitalRead(buttonPin1) == LOW) {
Keyboard.set_modifier(MODIFIERKEY_SHIFT | MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_N);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
//Led on
digitalWrite(ledPin1, HIGH); // LED on
delay(1000); // Fast blink
// Led off
digitalWrite(ledPin1, LOW);
}
if (digitalRead(buttonPin2) == LOW) {
Keyboard.set_modifier(MODIFIERKEY_SHIFT | MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_P);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
//Led on
digitalWrite(ledPin2, HIGH); // LED on
delay(1000); // Fast blink
// Led off
digitalWrite(ledPin2, LOW);
}
}
As you can see, I'm instructing to light a led for 1 second when a press is detected and I send a combination of keys to the computer.
Now, if the second button is pressed during that second, then nothing will happen.
Thus the question, is it possible to call an outside function for the led to light for one second, but in parallel continue the loop?
Thanks a lot for your help!
Cheers