The Code! Let's not forget the code!
OK so in order to make the microphone box work we need two separate pieces of code , both in Python, in order to make the adapters work and allow us to use the PTT buttons on the microphones.
In part one of this series ( https://apdelomni.blogspot.com/2023/10/cb-mic-to-pc-part-one.html ) we wrote the code for the Motorola adapter that translated serial CTS to a keypress.
Now we need the code to make the Adafruit QT Py RP2040 do the same thing! The process is a bit different in this case because we are making a USB device that identifies as a HID ( Vocab : Human Interface Device ) and sends a keypress when a GPIO ( Vocab : general-purpose input/output ) pin is closed. The code is very similar, only instead of running on your PC it will run on the QT Py and will need to be flashed into its memory.
What you will need :
Give the Adafruit guide to programming the QT Py a good read, and use the Mu editor. As always Adafruit has an amazing how-to for doing this at
https://learn.adafruit.com/adafruit-qt-py-2040/creating-and-editing-code
From there we just need the code to serve out needs! For this project we are using the G0 pin so we have wired the PTT button on the mic to G0 and GND as seen in the picture in our earlier part
https://apdelomni.blogspot.com/2023/10/prototype-breaker-breaker-any-takers.html
So now on to the code!
-------------------------
import board
import keypad
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
pins = [board.A0]
buttons = keypad.Keys(pins, value_when_pressed=False)
keyboard = Keyboard(usb_hid.devices)
event = keypad.Event()
print("listening")
while True:
while buttons.events:
buttons.events.get_into(event)
if event.pressed:
keyboard.press(Keycode.SHIFT,Keycode.F2)
print("PRESSED")
else:
keyboard.release(Keycode.SHIFT,Keycode.F2)
Comments
Post a Comment