#include <OneButton.h>
#include <MIDI.h>
#define LED_PIN 6
#define BUTTON_PIN 2
byte lastButtonState;
byte ledState = LOW;
unsigned long lastTimeButtonStateChanged = millis();
unsigned long debounceDuration = 50; // millis
// configure buttons
OneButton button1(2, true, true);
OneButton button2(3, true, true);
OneButton button3(4, true, true);
OneButton button4(5, true, true);
// Create and bind the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
// button 1
button1.attachClick(button1Press);
button1.attachDoubleClick(doubleclick1);
button1.attachLongPressStart(button1LongPressStart);
// button 2
button2.attachClick(button2Press);
button2.attachDoubleClick(doubleclick2);
button2.attachLongPressStart(button2LongPressStart);
// button 3
button3.attachClick(button3Press);
button3.attachDoubleClick(doubleclick3);
button3.attachLongPressStart(button3LongPressStart);
// button 4
button4.attachClick(button4Press);
button4.attachLongPressStart(button4LongPressStart);
// MIDI setup
MIDI.begin();
}
void loop() {
if (millis() - lastTimeButtonStateChanged >= debounceDuration) {
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastTimeButtonStateChanged = millis();
lastButtonState = buttonState;
if (buttonState == LOW) { // release
if (ledState == HIGH) {
ledState = LOW;
}
else {
ledState = HIGH;
}
digitalWrite(LED_PIN, ledState);
}
}
}
}
button1.tick();
button2.tick();
button3.tick();
button4.tick();
// TODO: do we need the delay here as in the example?
}
// button 1 Events
void button1Press() {
// Snapshot 1
MIDI.sendControlChange(69, 0, 1);
}
void doubleclick1() {
//FS 5
MIDI.sendControlChange(53, 1, 1);
}
void button1LongPressStart() {
// Preset Dwn
MIDI.sendControlChange(72, 0, 1);
}
// button 2 Events
void button2Press() {
// Snapshot 2
MIDI.sendControlChange(69, 1, 1);
}
void doubleclick2() {
//FS 4
MIDI.sendControlChange(52, 1, 1);
}
void button2LongPressStart() {
// Preset Up
MIDI.sendControlChange(72, 127, 1);
}
// button 3 Events
void button3Press() {
// Snapshot 3
MIDI.sendControlChange(69, 2, 1);
}
void doubleclick3() {
//Prev Mode
MIDI.sendControlChange(71, 5, 1);
}
void button3LongPressStart() {
// Next Mode
MIDI.sendControlChange(71, 4, 1);
}
// button 4 Events
void button4Press() {
// Tap tempo
MIDI.sendControlChange(64, 127, 1);
}
void button4LongPressStart() {
// show tuner
MIDI.sendControlChange(68, 0, 1);
}
At the very least, your code is messed up because of some mismatched or missing { braces }.
In the IDE, apply the Autoformat tool.
Then use the "Copy for Forum" tool on the sketch, and come here and paste in in your next posting to this thread.
Autoformat can help you spot structural syntax errors.
Posting code here properly means more ppl will even look at it, let alone analysis and such.
a7
Welcome to the forum
Please edit your post and add code tags around the error message and the code to make them easier to deal with
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum
thanks I've never posted here before
Hi @stringvelocity ,
Welcome to the forum..
Got one too many } and need function declarations added before setup..
Compiles, didn't take it any further..
#include <OneButton.h>
#include <MIDI.h>
#define LED_PIN 6
#define BUTTON_PIN 2
byte lastButtonState;
byte ledState = LOW;
unsigned long lastTimeButtonStateChanged = millis();
unsigned long debounceDuration = 50; // millis
// configure buttons
OneButton button1(2, true, true);
OneButton button2(3, true, true);
OneButton button3(4, true, true);
OneButton button4(5, true, true);
// Create and bind the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
void button1Press();
void doubleclick1();
void button1LongPressStart();
void button2Press();
void doubleclick2();
void button2LongPressStart();
void button3Press();
void doubleclick3();
void button3LongPressStart();
void button4Press();
void doubleclick4();
void button4LongPressStart();
void setup() {
// button 1
button1.attachClick(button1Press);
button1.attachDoubleClick(doubleclick1);
button1.attachLongPressStart(button1LongPressStart);
// button 2
button2.attachClick(button2Press);
button2.attachDoubleClick(doubleclick2);
button2.attachLongPressStart(button2LongPressStart);
// button 3
button3.attachClick(button3Press);
button3.attachDoubleClick(doubleclick3);
button3.attachLongPressStart(button3LongPressStart);
// button 4
button4.attachClick(button4Press);
button4.attachLongPressStart(button4LongPressStart);
// MIDI setup
MIDI.begin();
}
void loop() {
if (millis() - lastTimeButtonStateChanged >= debounceDuration) {
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastTimeButtonStateChanged = millis();
lastButtonState = buttonState;
if (buttonState == LOW) { // release
if (ledState == HIGH) {
ledState = LOW;
}
else {
ledState = HIGH;
}
digitalWrite(LED_PIN, ledState);
}
}
}
button1.tick();
button2.tick();
button3.tick();
button4.tick();
// TODO: do we need the delay here as in the example?
}
// button 1 Events
void button1Press() {
// Snapshot 1
MIDI.sendControlChange(69, 0, 1);
}
void doubleclick1() {
//FS 5
MIDI.sendControlChange(53, 1, 1);
}
void button1LongPressStart() {
// Preset Dwn
MIDI.sendControlChange(72, 0, 1);
}
// button 2 Events
void button2Press() {
// Snapshot 2
MIDI.sendControlChange(69, 1, 1);
}
void doubleclick2() {
//FS 4
MIDI.sendControlChange(52, 1, 1);
}
void button2LongPressStart() {
// Preset Up
MIDI.sendControlChange(72, 127, 1);
}
// button 3 Events
void button3Press() {
// Snapshot 3
MIDI.sendControlChange(69, 2, 1);
}
void doubleclick3() {
//Prev Mode
MIDI.sendControlChange(71, 5, 1);
}
void button3LongPressStart() {
// Next Mode
MIDI.sendControlChange(71, 4, 1);
}
// button 4 Events
void button4Press() {
// Tap tempo
MIDI.sendControlChange(64, 127, 1);
}
void button4LongPressStart() {
// show tuner
MIDI.sendControlChange(68, 0, 1);
}
have fun.. ~q
Why ?
I removed
have fun.. ~q
from @qubits-us's formatted code. It compiles.
The function prototypes are not necessary in the wokwi simulator, unknown equivalent IDE version.
Perhaps @qubits-us ran into one of the still seen but thankfully more rare preprocessor flaws and prototypes were the solution.
The original sketch now formatted and replacing the entirety of @stringvelocity's post #1 curiously does not compile and starts to look like you need prototypes.
But if you fix one extra or missing brace, it compiles without prototypes.
In my experience, missing prototypes tend to be the reddest of herrings. It looks like all it would take was supplying them, but it is a never-ending futile chore, unnecessary in most cases these days.
a7
probably, because i fixed it one error at a time..
really probably just had to remove the extra } maybe??
but you're right, i should be working..
have fun.. ~q
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.