PaulS:
if (digitalRead(switchPin) == LOW) // check if button was pressed
{
buttonPresses++; // increment buttonPresses count
delay(600); // debounce switch
}
You do NOT want to increment the counter when the pin IS low. You want to increment when the pin BECOMES low. Look at the state change detection example. A 600 millisecond delay is not debouncing.
But I have the Pin set high if the button is not pressed. so Why it should not be counted when its low?
600ms is because I don't want to allow the button being pressed that frequently.
I will try to send text to confirm if the connection works.
Oh I tried this code. Its a random Key/ Random Delay. And this worked.
/* Arduino USB HID Keyboard Demo
* Random Key/Random Delay
*/
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}
void loop()
{
int randomChar = random(4, 130);
long randomDelay = random(1000, 10000);
delay(randomDelay);
buf[2] = randomChar; // Random character
Serial.write(buf, 8); // Send keypress
releaseKey();
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}