Actually change pitch, fix VBand LED

* Fix VBand compatability LED
* Make it actually change pitch
This commit is contained in:
Neale Pickett 2023-02-25 18:10:14 -07:00
parent b04428276d
commit 31bfadd71d
7 changed files with 159 additions and 19 deletions

View File

@ -32,7 +32,10 @@ License: MIT
Things I plan to add: 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 # Contributing

View File

@ -10,9 +10,11 @@
#define SECOND (1000 * MILLISECOND) #define SECOND (1000 * MILLISECOND)
VailAdapter::VailAdapter(unsigned int PiezoPin) { VailAdapter::VailAdapter(unsigned int PiezoPin) {
this->keyboardMode = true;
this->buzzer = new PolyBuzzer(PiezoPin); this->buzzer = new PolyBuzzer(PiezoPin);
this->txToneFrequency = 440; }
bool VailAdapter::KeyboardMode() {
return this->keyboardMode;
} }
// Send a MIDI Key Event // Send a MIDI Key Event
@ -33,7 +35,7 @@ void VailAdapter::keyboardKey(uint8_t key, bool down) {
// Begin transmitting // Begin transmitting
void VailAdapter::BeginTx() { void VailAdapter::BeginTx() {
this->buzzer->Tone(0, this->txToneFrequency); this->buzzer->Note(0, this->txNote);
if (this->keyboardMode) { if (this->keyboardMode) {
this->keyboardKey(KEY_LEFT_CTRL, true); this->keyboardKey(KEY_LEFT_CTRL, true);
} else { } else {
@ -102,6 +104,9 @@ void VailAdapter::HandleMIDI(midiEventPacket_t event) {
this->keyer->SetDitDuration(this->ditDuration); this->keyer->SetDitDuration(this->ditDuration);
} }
break; break;
case 2: // set tx note
this->txNote = event.byte3;
break;
} }
break; break;
case 0xC0: // Program Change case 0xC0: // Program Change

View File

@ -6,9 +6,9 @@
class VailAdapter: public Transmitter { class VailAdapter: public Transmitter {
private: private:
unsigned int txToneFrequency; unsigned int txNote = 69;
unsigned int ditDuration = 100; unsigned int ditDuration = 100;
bool keyboardMode = false; bool keyboardMode = true;
Keyer *keyer = NULL; Keyer *keyer = NULL;
PolyBuzzer *buzzer = NULL; PolyBuzzer *buzzer = NULL;
@ -18,6 +18,7 @@ private:
public: public:
VailAdapter(unsigned int PiezoPin); VailAdapter(unsigned int PiezoPin);
bool KeyboardMode();
void HandlePaddle(Paddle key, bool pressed); void HandlePaddle(Paddle key, bool pressed);
void HandleMIDI(midiEventPacket_t event); void HandleMIDI(midiEventPacket_t event);
void BeginTx(); void BeginTx();

132
equal_temperament.h Normal file
View File

@ -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
};

View File

@ -1,5 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "polybuzzer.h" #include "polybuzzer.h"
#include "equal_temperament.h"
PolyBuzzer::PolyBuzzer(uint8_t pin) { PolyBuzzer::PolyBuzzer(uint8_t pin) {
for (int i = 0; i < POLYBUZZER_MAX_TONES; i++) { for (int i = 0; i < POLYBUZZER_MAX_TONES; i++) {
@ -12,10 +13,10 @@ PolyBuzzer::PolyBuzzer(uint8_t pin) {
void PolyBuzzer::update() { void PolyBuzzer::update() {
for (int i = 0; i < POLYBUZZER_MAX_TONES; i++) { for (int i = 0; i < POLYBUZZER_MAX_TONES; i++) {
if (tones[i]) { if (this->tones[i]) {
if (playing != tones[i]) { if (this->playing != this->tones[i]) {
playing = tones[i]; this->playing = this->tones[i];
tone(this->pin, tones[i]); tone(this->pin, this->tones[i]);
} }
return; return;
} }
@ -25,16 +26,15 @@ void PolyBuzzer::update() {
} }
void PolyBuzzer::Tone(int slot, unsigned int frequency) { void PolyBuzzer::Tone(int slot, unsigned int frequency) {
tones[slot] = frequency; this->tones[slot] = frequency;
this->update(); this->update();
} }
void PolyBuzzer::Note(int slot, int note) { void PolyBuzzer::Note(int slot, uint8_t note) {
unsigned int frequency = 8.18; // MIDI note 0 if (note > 127) {
for (int i = 0; i < note; i++) { note = 127;
frequency *= 1.0594630943592953; // equal temperament half step
} }
this->Tone(slot, frequency); this->Tone(slot, equalTemperamentNote[note]);
} }
void PolyBuzzer::NoTone(int slot) { void PolyBuzzer::NoTone(int slot) {

View File

@ -15,6 +15,6 @@ public:
PolyBuzzer(uint8_t pin); PolyBuzzer(uint8_t pin);
void update(); void update();
void Tone(int slot, unsigned int frequency); void Tone(int slot, unsigned int frequency);
void Note(int slot, int note); void Note(int slot, uint8_t note);
void NoTone(int slot); void NoTone(int slot);
}; };

View File

@ -27,7 +27,6 @@
#define MILLISECOND 1 #define MILLISECOND 1
#define SECOND (1 * MILLISECOND) #define SECOND (1 * MILLISECOND)
bool keyboard = true;
bool trs = false; // true if a TRS plug is in a TRRS jack bool trs = false; // true if a TRS plug is in a TRRS jack
uint16_t iambicDelay = 80 * MILLISECOND; uint16_t iambicDelay = 80 * MILLISECOND;
Bounce dit = Bounce(); Bounce dit = Bounce();
@ -69,7 +68,7 @@ void setup() {
void setLED() { void setLED() {
static bool beepin = false; static bool beepin = false;
int beat = millis() / iambicDelay; 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) { if (beat < 16) {
on = HELLO_BITS & (1 << (15-beat)); on = HELLO_BITS & (1 << (15-beat));