Skip to main content

How to tell Arduino Uno that I pressed or released a key on PC keyboard over serial?

I want to implement a simple musical keyboard with Arduino using tone() and noTone() functions, etc.

The desired behavior is:

  • While PC and Arduino are connected via USB/Serial...
  • ...when I press a key, a corresponding note starts playing...
  • ...and if I release that key that note stops playing...
  • ...or if I press another key, another note replaces the former one.

So, basically, isteadinstead of "while key is pressed" logic, I would like to just write a byte to serial when a key is pressed, write nothing while the key is held pressed, and write another byte when that key is released.

I will be using a pythonPython script in the PC, but examples in other languages, or just using a plain serial monitor, are fine.

How tell Arduino Uno that I pressed or released a key on PC keyboard over serial?

I want to implement a simple musical keyboard with Arduino using tone() and noTone() functions, etc.

The desired behavior is:

  • While PC and Arduino are connected via USB/Serial...
  • ...when I press a key, a corresponding note starts playing...
  • ...and if I release that key that note stops playing...
  • ...or if I press another key, another note replaces the former one.

So, basically, istead of "while key is pressed" logic, I would like to just write a byte to serial when a key is pressed, write nothing while the key is held pressed, and write another byte when that key is released.

I will be using a python script in the PC, but examples in other languages, or just using a plain serial monitor, are fine.

How to tell Arduino Uno that I pressed or released a key on PC keyboard over serial?

I want to implement a simple musical keyboard with Arduino using tone() and noTone() functions, etc.

The desired behavior is:

  • While PC and Arduino are connected via USB/Serial...
  • ...when I press a key, a corresponding note starts playing...
  • ...and if I release that key that note stops playing...
  • ...or if I press another key, another note replaces the former one.

So, basically, instead of "while key is pressed" logic, I would like to just write a byte to serial when a key is pressed, write nothing while the key is held pressed, and write another byte when that key is released.

I will be using a Python script in the PC, but examples in other languages, or just using a plain serial monitor, are fine.

Source Link
heltonbiker
  • 503
  • 7
  • 21

How tell Arduino Uno that I pressed or released a key on PC keyboard over serial?

I want to implement a simple musical keyboard with Arduino using tone() and noTone() functions, etc.

The desired behavior is:

  • While PC and Arduino are connected via USB/Serial...
  • ...when I press a key, a corresponding note starts playing...
  • ...and if I release that key that note stops playing...
  • ...or if I press another key, another note replaces the former one.

So, basically, istead of "while key is pressed" logic, I would like to just write a byte to serial when a key is pressed, write nothing while the key is held pressed, and write another byte when that key is released.

I will be using a python script in the PC, but examples in other languages, or just using a plain serial monitor, are fine.