From ed8d884054fdf7294fe8be1aab34254563c55f3e Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 10 Jan 2024 08:46:38 -0700 Subject: [PATCH] Looks like I forgot to add my changes? --- MockBand.ino | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/MockBand.ino b/MockBand.ino index 8794bd6..958a7d8 100644 --- a/MockBand.ino +++ b/MockBand.ino @@ -2,11 +2,11 @@ #include #include -//#define DEBUG +#define DEBUG #include "hid.hh" // Modified HID library: doesn't prefix each packet with ID #include "instrument.hh" -#include "standard.hh" // Standard pins +#include "piezos.hh" // If defined, we will check the wammy bar input //#define WAMMY @@ -41,23 +41,17 @@ InstrumentButtonState buttonState = {0}; void setup() { - pinMode(STRUM_DOWN, INPUT_PULLUP); - pinMode(STRUM_UP, INPUT_PULLUP); - pinMode(TILT_SWITCH, INPUT_PULLUP); - pinMode(BUTTON_GREEN, INPUT_PULLUP); - pinMode(BUTTON_RED, INPUT_PULLUP); - pinMode(BUTTON_YELLOW, INPUT_PULLUP); - pinMode(BUTTON_BLUE, INPUT_PULLUP); + pinMode(BUTTON_GREEN, INPUT); + pinMode(BUTTON_RED, INPUT); + pinMode(BUTTON_YELLOW, INPUT); + pinMode(BUTTON_BLUE, INPUT); pinMode(BUTTON_ORANGE, INPUT_PULLUP); - pinMode(SOLO_GREEN, INPUT_PULLUP); - pinMode(SOLO_RED, INPUT_PULLUP); - pinMode(SOLO_YELLOW, INPUT_PULLUP); - pinMode(SOLO_BLUE, INPUT_PULLUP); - pinMode(SOLO_ORANGE, INPUT_PULLUP); + pinMode(SOLO_GREEN, INPUT); + pinMode(SOLO_RED, INPUT); + pinMode(SOLO_YELLOW, INPUT); + pinMode(SOLO_BLUE, INPUT); pinMode(BUTTON_PLUS, INPUT_PULLUP); pinMode(BUTTON_MINUS, INPUT_PULLUP); - pinMode(ANALOG_WAMMY, INPUT); - pinMode(ANALOG_DPAD, INPUT); // Initialize HID static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); @@ -86,10 +80,13 @@ uint8_t pins[] = { }; #define npins (sizeof(pins) / sizeof(*pins)) +#define NOISE_THRESHOLD 40 // Minimum analog value to treat as a hit + // The 3.3v Pro Micro is on the slow side. // Our strategy is to poll button state as quickly as possible, // and hope we don't miss anything while we're doing USB stuff. void loop() { + uint16_t inputs[16] = {0}; uint16_t buttons = 0; uint16_t samples = 0; unsigned long next = 0; @@ -99,13 +96,20 @@ void loop() { uint16_t edge = 0; samples++; + inputs[0] = analogRead(INPUT_BLUE); + inputs[1] = analogRead(INPUT_GREEN); + inputs[2] = analogRead(INPUT_RED); + inputs[3] = analogRead(INPUT_YELLOW); - for (uint8_t i = 0; i < npins; i++) { + for (uint8_t i = 0; i < 4; i++) { if (silence[i]) { silence[i]--; - } else if (bitRead(buttons, i) != !digitalRead(pins[i])) { - edge |= bit(i); - silence[i] = SILENCE_SAMPLES; + } else { + bool trigger = inputs[i] > NOISE_THRESHOLD; + if (trigger != bitRead(buttons, i)) { + edge |= bit(i); + silence[i] = SILENCE_SAMPLES; + } } } buttons ^= edge; @@ -147,10 +151,10 @@ void loop() { buttonState.axis[3] = bitRead(buttons, 12)?255:0; // High hat // rbdrum2midi wants these set - buttonState.velocity[0] = bitRead(buttonState.buttons, 3)?127:0; // Y - buttonState.velocity[1] = bitRead(buttonState.buttons, 2)?127:0; // R - buttonState.velocity[2] = bitRead(buttonState.buttons, 1)?127:0; // G - buttonState.velocity[3] = bitRead(buttonState.buttons, 0)?127:0; // B + buttonState.velocity[0] = inputs[3]/4; // Y + buttonState.velocity[1] = inputs[2]/4; // R + buttonState.velocity[2] = inputs[1]/2; // G + buttonState.velocity[3] = inputs[0]/4; // B // Say the D-pad is centered buttonState.hatAndConstant = 8;