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.