Hello,
I am trying to program some kind of pageturner with a Teensy LC with Arduino IDE 2.1.1
.
I use the digital ports 1, 2, 3, ..., 6. The following key codes should be sent to a Windows PC:
1 - KEY_LEFT
2 - KEY_RIGHT
3 - KEY_HOME
4 - KEY_END
5 - KEY_PAGE_UP
6 - KEY_PAGE_DOWN
The program runs, but on the PC (tested with an editor) not the desired keys arrive but only letters (1 - P, 2 - O, 3 - J, ...).
Where is my error?
Many greetings
Volker
Here is my code:
I am trying to program some kind of pageturner with a Teensy LC with Arduino IDE 2.1.1
Code:
I use the digital ports 1, 2, 3, ..., 6. The following key codes should be sent to a Windows PC:
1 - KEY_LEFT
2 - KEY_RIGHT
3 - KEY_HOME
4 - KEY_END
5 - KEY_PAGE_UP
6 - KEY_PAGE_DOWN
The program runs, but on the PC (tested with an editor) not the desired keys arrive but only letters (1 - P, 2 - O, 3 - J, ...).
Where is my error?
Many greetings
Volker
Here is my code:
Code:
#include <Keyboard.h>
#include <ezButton.h>
/* Keys
1 KEY_LEFT_ARROW
2 KEY_RIGHT_ARROW
3 KEY_HOME
4 KEY_END
5 KEY_PAGE_UP
6 KEY_PAGE_DOWN
*/
const byte Foot1 = 1;
const byte Foot2 = 2;
const byte Foot3 = 3;
const byte Foot4 = 4;
const byte Foot5 = 5;
const byte Foot6 = 6;
const byte LEDbuildin = 13;
byte Foot1state = HIGH;
byte Foot2state = HIGH;
byte Foot3state = HIGH;
byte Foot4state = HIGH;
byte Foot5state = HIGH;
byte Foot6state = HIGH;
ezButton deb1(Foot1);
ezButton deb2(Foot2);
ezButton deb3(Foot3);
ezButton deb4(Foot4);
ezButton deb5(Foot5);
ezButton deb6(Foot6);
void setup()
{
pinMode(Foot1, INPUT_PULLUP); // links Port 1
deb1.setDebounceTime(25);
pinMode(Foot2, INPUT_PULLUP); // rechts Port 2
deb2.setDebounceTime(25);
pinMode(Foot3, INPUT_PULLUP); // links Port 1
deb3.setDebounceTime(25);
pinMode(Foot4, INPUT_PULLUP); // rechts Port 2
deb4.setDebounceTime(25);
pinMode(Foot5, INPUT_PULLUP); // links Port 1
deb5.setDebounceTime(25);
pinMode(Foot6, INPUT_PULLUP); // rechts Port 2
deb6.setDebounceTime(25);
pinMode(LEDbuildin, OUTPUT); // LED Port 1
digitalWrite(LEDbuildin, LOW);
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
deb1.loop();
deb2.loop();
deb3.loop();
deb4.loop();
deb5.loop();
deb6.loop();
int debo1 = deb1.getState();
int debo2 = deb2.getState();
int debo3 = deb3.getState();
int debo4 = deb4.getState();
int debo5 = deb5.getState();
int debo6 = deb6.getState();
if (debo1 == LOW && Foot1state == HIGH)
{
digitalWrite(LEDbuildin, HIGH);
//delay(80);
Foot1state = LOW;
Keyboard.write(KEY_LEFT);
}
if (debo1 == HIGH && Foot1state == LOW)
{
digitalWrite(LEDbuildin, LOW);
//delay(80);
Foot1state = HIGH;
}
if (debo2 == LOW && Foot2state == HIGH)
{
digitalWrite(LEDbuildin, HIGH);
//delay(80);
Foot2state = LOW;
Keyboard.write(KEY_RIGHT);
}
if (debo2 == HIGH && Foot2state == LOW)
{
digitalWrite(LEDbuildin, LOW);
//delay(80);
Foot2state = HIGH;
}
if (debo3 == LOW && Foot3state == HIGH)
{
digitalWrite(LEDbuildin, HIGH);
//delay(80);
Foot3state = LOW;
Keyboard.write(KEY_HOME);
}
if (debo3 == HIGH && Foot3state == LOW)
{
digitalWrite(LEDbuildin, LOW);
//delay(80);
Foot3state = HIGH;
}
if (debo4 == LOW && Foot4state == HIGH)
{
digitalWrite(LEDbuildin, HIGH);
//delay(80);
Foot4state = LOW;
Keyboard.write(KEY_END);
}
if (debo4 == HIGH && Foot4state == LOW)
{
digitalWrite(LEDbuildin, LOW);
//delay(80);
Foot4state = HIGH;
}
if (debo5 == LOW && Foot5state == HIGH)
{
digitalWrite(LEDbuildin, HIGH);
//delay(80);
Foot5state = LOW;
Keyboard.write(KEY_PAGE_UP);
}
if (debo5 == HIGH && Foot5state == LOW)
{
digitalWrite(LEDbuildin, LOW);
//delay(80);
Foot5state = HIGH;
}
if (debo6 == LOW && Foot6state == HIGH)
{
digitalWrite(LEDbuildin, HIGH);
//delay(80);
Foot6state = LOW;
Keyboard.write(KEY_PAGE_DOWN);
}
if (debo6 == HIGH && Foot6state == LOW)
{
digitalWrite(LEDbuildin, LOW);
//delay(80);
Foot6state = HIGH;
}
}