Good point.
I will get to it once I have some hope to get the counter thing working.
So here is a code that works.
It sends a R each time I press the button. A0 is pulled low with resistor and goes high once the button is pressed.
/*
*
*/
//9.Aprill, 2000
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
const int button = A0; // Button input pin
int ButtonState = LOW; //
int val = 0; // button value
void setup()
{
Serial.begin(9600);
pinMode(button, INPUT);
delay(200);
}
void loop()
{
val = digitalRead(button); // read the button
delay(300); // wait, to reduce noise (debouncing stuff)
if (val == HIGH) // continue if the button is pressed
{
buf[2] = 0x15; // Letter R
Serial.write(buf, 8); // Send keypress
releaseKey();
}
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}
The next step would be to get the thing sending other letters or numbers (I actually need nubers from 0 to 9)
I was first thinking to program a counter. And use If/else if functions to send different numbers to PC.
I also found out that if I use Serial.print in the code and switch to Arduino keyboard, the thing will go nuts.