33#include <Arduino.h>
44#include "Adafruit_TinyUSB.h"
55#include "globals.h"
6- extern volatile uint16_t voiceLastReading; // In pdmvoice.cpp
6+ extern volatile uint16_t voiceLastReading, voiceMin, voiceMax ; // In pdmvoice.cpp
77
88#define UP_BUTTON_KEYCODE_TO_SEND HID_KEY_U
99#define A_BUTTON_KEYCODE_TO_SEND HID_KEY_A
@@ -13,7 +13,7 @@ extern volatile uint16_t voiceLastReading; // In pdmvoice.cpp
1313// even if not using sound output...we're using it to steal
1414// access to the mic here.
1515#define SOUND_KEYCODE_TO_SEND HID_KEY_SPACE
16- #define SOUND_THRESHOLD 1000
16+ #define SOUND_THRESHOLD 10000
1717
1818// HID report descriptor using TinyUSB's template
1919// Single Report (no ID) descriptor
@@ -67,13 +67,14 @@ void user_loop(void) {
6767 keycode[3] = SHAKE_KEYCODE_TO_SEND;
6868 }
6969
70- if(voiceLastReading) { // usu. non-zero if voice changer enabled
71- int level = abs((int32_t)voiceLastReading - 32768);
72- if(level > SOUND_THRESHOLD) {
70+ uint16_t p2p = voiceMax - voiceMin; // Max peak-to-peak since last reading
71+ if(p2p) { // usu. non-zero if voice changer enabled
72+ if(p2p > SOUND_THRESHOLD) {
7373 Serial.println("Sound");
7474 keycode[4] = SOUND_KEYCODE_TO_SEND;
7575 }
7676 }
77+ voiceMin = voiceMax = 32768; // Reset p2p range for next pass
7778
7879 bool anypressed = false;
7980 for (int k=0; k<sizeof(keycode); k++) {
0 commit comments