From 31bfadd71d69769782400d0dcc3a9797a8b4f8fd Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sat, 25 Feb 2023 18:10:14 -0700 Subject: [PATCH] Actually change pitch, fix VBand LED * Fix VBand compatability LED * Make it actually change pitch --- README.md | 5 +- adapter.cpp | 11 +++- adapter.h | 5 +- equal_temperament.h | 132 ++++++++++++++++++++++++++++++++++++++++++++ polybuzzer.cpp | 20 +++---- polybuzzer.h | 2 +- vail-adapter.ino | 3 +- 7 files changed, 159 insertions(+), 19 deletions(-) create mode 100644 equal_temperament.h diff --git a/README.md b/README.md index 32855c5..f380530 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,10 @@ License: MIT Things I plan to add: -* PCB to ease assembly and make a more robust shippable product +* [x] PCB to ease assembly and make a more robust shippable product +* [ ] Debug tone changes +* [ ] PCB v2 to get the speaker on pin 10 instead of pin 9 +* [ ] Unplug detection: send a pulse out one pin and detect it on the T pin to reset straight-key detection # Contributing diff --git a/adapter.cpp b/adapter.cpp index 865838b..a53946f 100644 --- a/adapter.cpp +++ b/adapter.cpp @@ -10,9 +10,11 @@ #define SECOND (1000 * MILLISECOND) VailAdapter::VailAdapter(unsigned int PiezoPin) { - this->keyboardMode = true; this->buzzer = new PolyBuzzer(PiezoPin); - this->txToneFrequency = 440; +} + +bool VailAdapter::KeyboardMode() { + return this->keyboardMode; } // Send a MIDI Key Event @@ -33,7 +35,7 @@ void VailAdapter::keyboardKey(uint8_t key, bool down) { // Begin transmitting void VailAdapter::BeginTx() { - this->buzzer->Tone(0, this->txToneFrequency); + this->buzzer->Note(0, this->txNote); if (this->keyboardMode) { this->keyboardKey(KEY_LEFT_CTRL, true); } else { @@ -102,6 +104,9 @@ void VailAdapter::HandleMIDI(midiEventPacket_t event) { this->keyer->SetDitDuration(this->ditDuration); } break; + case 2: // set tx note + this->txNote = event.byte3; + break; } break; case 0xC0: // Program Change diff --git a/adapter.h b/adapter.h index 89dfe98..97cdc9c 100644 --- a/adapter.h +++ b/adapter.h @@ -6,9 +6,9 @@ class VailAdapter: public Transmitter { private: - unsigned int txToneFrequency; + unsigned int txNote = 69; unsigned int ditDuration = 100; - bool keyboardMode = false; + bool keyboardMode = true; Keyer *keyer = NULL; PolyBuzzer *buzzer = NULL; @@ -18,6 +18,7 @@ private: public: VailAdapter(unsigned int PiezoPin); + bool KeyboardMode(); void HandlePaddle(Paddle key, bool pressed); void HandleMIDI(midiEventPacket_t event); void BeginTx(); diff --git a/equal_temperament.h b/equal_temperament.h new file mode 100644 index 0000000..70095a3 --- /dev/null +++ b/equal_temperament.h @@ -0,0 +1,132 @@ +#pragma once + +const int equalTemperamentNote[] = { + 8, // 0 + 8, // 1 + 9, // 2 + 9, // 3 + 10, // 4 + 10, // 5 + 11, // 6 + 12, // 7 + 12, // 8 + 13, // 9 + 14, // 10 + 15, // 11 + 16, // 12 + 17, // 13 + 18, // 14 + 19, // 15 + 20, // 16 + 21, // 17 + 23, // 18 + 24, // 19 + 25, // 20 + 27, // 21 + 29, // 22 + 30, // 23 + 32, // 24 + 34, // 25 + 36, // 26 + 38, // 27 + 41, // 28 + 43, // 29 + 46, // 30 + 49, // 31 + 51, // 32 + 55, // 33 + 58, // 34 + 61, // 35 + 65, // 36 + 69, // 37 + 73, // 38 + 77, // 39 + 82, // 40 + 87, // 41 + 92, // 42 + 98, // 43 + 103, // 44 + 110, // 45 + 116, // 46 + 123, // 47 + 130, // 48 + 138, // 49 + 146, // 50 + 155, // 51 + 164, // 52 + 174, // 53 + 185, // 54 + 196, // 55 + 207, // 56 + 220, // 57 + 233, // 58 + 247, // 59 + 261, // 60 + 277, // 61 + 293, // 62 + 311, // 63 + 329, // 64 + 349, // 65 + 370, // 66 + 392, // 67 + 415, // 68 + 440, // 69 + 466, // 70 + 494, // 71 + 523, // 72 + 554, // 73 + 587, // 74 + 622, // 75 + 659, // 76 + 698, // 77 + 740, // 78 + 784, // 79 + 831, // 80 + 880, // 81 + 932, // 82 + 988, // 83 + 1047, // 84 + 1109, // 85 + 1175, // 86 + 1245, // 87 + 1319, // 88 + 1397, // 89 + 1480, // 90 + 1568, // 91 + 1662, // 92 + 1760, // 93 + 1865, // 94 + 1976, // 95 + 2094, // 96 + 2218, // 97 + 2350, // 98 + 2490, // 99 + 2638, // 100 + 2795, // 101 + 2961, // 102 + 3137, // 103 + 3324, // 104 + 3521, // 105 + 3731, // 106 + 3953, // 107 + 4188, // 108 + 4437, // 109 + 4701, // 110 + 4980, // 111 + 5276, // 112 + 5590, // 113 + 5922, // 114 + 6275, // 115 + 6648, // 116 + 7043, // 117 + 7462, // 118 + 7906, // 119 + 8376, // 120 + 8874, // 121 + 9402, // 122 + 9961, // 123 + 10553, // 124 + 11181, // 125 + 11845, // 126 + 12550, // 127 +}; diff --git a/polybuzzer.cpp b/polybuzzer.cpp index 6f6310b..57e583b 100644 --- a/polybuzzer.cpp +++ b/polybuzzer.cpp @@ -1,5 +1,6 @@ #include #include "polybuzzer.h" +#include "equal_temperament.h" PolyBuzzer::PolyBuzzer(uint8_t pin) { for (int i = 0; i < POLYBUZZER_MAX_TONES; i++) { @@ -12,10 +13,10 @@ PolyBuzzer::PolyBuzzer(uint8_t pin) { void PolyBuzzer::update() { for (int i = 0; i < POLYBUZZER_MAX_TONES; i++) { - if (tones[i]) { - if (playing != tones[i]) { - playing = tones[i]; - tone(this->pin, tones[i]); + if (this->tones[i]) { + if (this->playing != this->tones[i]) { + this->playing = this->tones[i]; + tone(this->pin, this->tones[i]); } return; } @@ -25,16 +26,15 @@ void PolyBuzzer::update() { } void PolyBuzzer::Tone(int slot, unsigned int frequency) { - tones[slot] = frequency; + this->tones[slot] = frequency; this->update(); } -void PolyBuzzer::Note(int slot, int note) { - unsigned int frequency = 8.18; // MIDI note 0 - for (int i = 0; i < note; i++) { - frequency *= 1.0594630943592953; // equal temperament half step +void PolyBuzzer::Note(int slot, uint8_t note) { + if (note > 127) { + note = 127; } - this->Tone(slot, frequency); + this->Tone(slot, equalTemperamentNote[note]); } void PolyBuzzer::NoTone(int slot) { diff --git a/polybuzzer.h b/polybuzzer.h index 2b50065..41eca6e 100644 --- a/polybuzzer.h +++ b/polybuzzer.h @@ -15,6 +15,6 @@ public: PolyBuzzer(uint8_t pin); void update(); void Tone(int slot, unsigned int frequency); - void Note(int slot, int note); + void Note(int slot, uint8_t note); void NoTone(int slot); }; diff --git a/vail-adapter.ino b/vail-adapter.ino index a7901a7..9cd6581 100644 --- a/vail-adapter.ino +++ b/vail-adapter.ino @@ -27,7 +27,6 @@ #define MILLISECOND 1 #define SECOND (1 * MILLISECOND) -bool keyboard = true; bool trs = false; // true if a TRS plug is in a TRRS jack uint16_t iambicDelay = 80 * MILLISECOND; Bounce dit = Bounce(); @@ -69,7 +68,7 @@ void setup() { void setLED() { static bool beepin = false; int beat = millis() / iambicDelay; - bool on = keyboard; // If we're not in intro, display status of keyboard + bool on = adapter.KeyboardMode(); // If we're not in intro, display status of keyboard if (beat < 16) { on = HELLO_BITS & (1 << (15-beat));