Dear all,
For a project I'm working on, I try to built a basic MIDI pedalboard prototype to send Start/Stop and Clock (Sync) MIDI messages, using two push buttons (one for the Tap Tempo, one for Start / Stop).
The idea is to sync Ableton Live (in a first "prototyping" time) and later (finally), a grandMA2 lighting console in order to synchronise lights with my full analog (no MIDI) modular synthetiser.
I spend lot of time searching on Teensy projects and forum and tried to "mix" two pieces of code.
This one : https://github.com/little-scale/arduino-sketches/blob/master/MIDI_Clock_Send_3.ino and this one : https://forum.arduino.cc/t/measuring-the-time-between-2-button-presses/584791/5 (Cattledog's answer / piece of code).
Both work great, separately (with Ableton Live).
My troubles begin when I try to have both working together and I can't figure where is the problem (or incompatibilities)...
Is it a "multiple Bounce functions" problem ?
Something in the organisation or timing of the code ?
Something completely else ? ;-)
A huge thanks for any help !
For a project I'm working on, I try to built a basic MIDI pedalboard prototype to send Start/Stop and Clock (Sync) MIDI messages, using two push buttons (one for the Tap Tempo, one for Start / Stop).
The idea is to sync Ableton Live (in a first "prototyping" time) and later (finally), a grandMA2 lighting console in order to synchronise lights with my full analog (no MIDI) modular synthetiser.
I spend lot of time searching on Teensy projects and forum and tried to "mix" two pieces of code.
This one : https://github.com/little-scale/arduino-sketches/blob/master/MIDI_Clock_Send_3.ino and this one : https://forum.arduino.cc/t/measuring-the-time-between-2-button-presses/584791/5 (Cattledog's answer / piece of code).
Both work great, separately (with Ableton Live).
My troubles begin when I try to have both working together and I can't figure where is the problem (or incompatibilities)...
Is it a "multiple Bounce functions" problem ?
Something in the organisation or timing of the code ?
Something completely else ? ;-)
A huge thanks for any help !
Code:
#include <Bounce2.h>
Bounce rpmSelectorButton = Bounce();
Bounce pushButton = Bounce();
float bpm; // ajout Nika
float delay_time;
int play_flag;
int pushButton_pin = 4;
int debounce_time = 10;
unsigned long startTime;
unsigned long currentTime;
unsigned long interval;
const byte buttonPin = 2;
boolean timing = false;
void setup()
{
// Serial.begin(115200);
pinMode(pushButton_pin, INPUT_PULLUP);
pushButton.attach(pushButton_pin);
pushButton.interval(debounce_time);
delay(3000);
pinMode(buttonPin, INPUT_PULLUP);
// Serial.println("Interval Timer Demo");
rpmSelectorButton.attach(buttonPin);
rpmSelectorButton.interval(debounce_time); // was debounce period in ms (25) // PROBLEM HERE ?
delay(3000);
}
void loop()
{
pushButton.update();
if (pushButton.fell() == true) {
play_flag = 1 - play_flag;
if (play_flag == 1) {
usbMIDI.sendRealTime(usbMIDI.Start);
Serial.println("MyLady_Clock : Start");
}
else {
usbMIDI.sendRealTime(usbMIDI.Stop);
Serial.println("MyLady_Clock : Stop");
}
}
currentTime = millis();
rpmSelectorButton.update();//debounced digitalRead()
if(rpmSelectorButton.fell() && ! timing)
{
startTime = currentTime;
timing = true;
// Serial.println("start interval timing ");
rpmSelectorButton.update();//ensures new debounce reading for second press
}
if (rpmSelectorButton.fell() && timing)
{
interval = millis() - startTime;
timing = false;
Serial.println("end interval timing");
Serial.print("Time between button presses ");
Serial.println(interval); // in milliseconds
bpm = (60000 / interval); // to calculate musical time / tempo
Serial.print("Lady BPM : ");
Serial.println(bpm);
delay_time = (60000000 / bpm) / 24; // to calculate Pulse Per Quarter note (MIDI clock)
Serial.print("delay_Time : ");
Serial.println(delay_time);
usbMIDI.sendRealTime(usbMIDI.Clock);
delayMicroseconds(delay_time);
// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
// while (usbMIDI.read()) {
// ignore incoming messages
// }
}
}
Last edited: