Skip to content

Instantly share code, notes, and snippets.

@CountParadox
Created February 8, 2023 11:31
Show Gist options
  • Save CountParadox/043fbe8538cb424069548208f3bb3e8c to your computer and use it in GitHub Desktop.
Save CountParadox/043fbe8538cb424069548208f3bb3e8c to your computer and use it in GitHub Desktop.
Digispark PTT Code
/*
This program will send USB HID keyboard presses to initiate
a PTT call with system of choice.
* Press and hold button 1 to activate PTT (Push-to-Talk) functionality.
*/
#include <DigiKeyboard.h> // Library for sending keystrokes as an HID device over USB
#include <OneButton.h> // Library for button input functions
OneButton button1(
0, // Pin Number
true, // Input is active LOW
true // Enable internal pull-up resistor
);
void setup() {
button1.attachLongPressStart(button1longPressStart); // Set up button 1 for ptt press
button1.attachLongPressStop(button1longPressStop); // Set up button 1 for ptt release
button1.setPressTicks(250); // Reduce long-press delay for button 1 to make ptt more responsive
DigiKeyboard.delay(50); // Delay before entering loop
}
void loop() {
DigiKeyboard.update(); // Maintain USB communication
button1.tick(); // Check status of buttons in a continuous loop
}
// This function will be called when button 1 is pressed and held down for more than 300ms.
void button1longPressStart() {
DigiKeyboard.sendKeyStroke(0); // Clear any current key presses
DigiKeyboard.sendKeyPress(0,MOD_ALT_LEFT); // Press and hold the F7 key to trigger ptt
}
// This function will be called when button 1 is released after being held down.
void button1longPressStop() {
DigiKeyboard.delay(300); // Delay to prevent cutting off the speaker's last word
DigiKeyboard.sendKeyPress(0); // Release F7 key to stop ptt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment