void loop() {
updateBreath();
updateNote();
updateCC();
if(state == STATE_NOTE_OFF) {
if(breath_measured > breath_threshold) {
breath_time = millis();
state = STATE_NOTE_NEW;
}
}
if(state == STATE_NOTE_NEW) {
if(breath_measured > breath_threshold) {
if(millis() > breath_time + breath_risetime) {
sendCC();
sendNoteOn(note_fingered);
cc_time = millis();
state = STATE_NOTE_ON
}
} else {
state = STATE_NOTE_OFF;
}
}
if(state == STATE_NOTE_ON) {
if(breath_measured > breath_threshold) {
if(millis() > cc_time + cc_delay) {
sendCC();
cc_time = millis();
}
if(note_fingered != note_playing) {
if(legato) {
note_temp = note_playing;
sendNoteOn(noteFingered);
sendNoteOff(note_temp);
} else {
sendNoteOff(note_playing);
sendNoteOn(note_fingered);
}
}
} else {
sendNoteOff(note_playing);
state = STATE_NOTE_OFF;
}
}
}
void updateNote() {
note_fingered_debounce = rawNote(); //Update from capacitive touch board
if(note_fingered_debounce != note_fingered) {
if(note_debounce) {
if(millis() > note_debounce_time + note_debounce_delay) {
note_fingered = note_fingered_debounce;
note_debounce = false;
}
} else {
note_debounce_time = millis();
note_debounce = true;
}
}
}
In the above snips of code you can see the main microcontroller loop, and the updateNote() function.
It's a dead simple state machine with only OFF, NEW and ON states. Every cycle of the loop we read the raw breath, update our fingered note, and calculate CC values.
The full version will have functions for the different programming modes and extra features, but the heart of the instrument is this loop.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.