#include "OneButton.h"
#include <MIDI.h>
#define PIN_INPUT 15
#define PIN_INPUT2 16
#define PIN_LED_2 10
#define PIN_LED_RED 11
#define PIN_LED_GREEN 12
#define PIN_LED_BLUE 13
// Setup a new OneButton on pin PIN_INPUT
// The 2. parameter activeLOW is true, because external wiring sets the button
// to LOW when pressed.
OneButton button(PIN_INPUT, true);
// current LED state, starting with LOW (0)
int ledState = LOW;
// current button and old button state
int buttonState = HIGH;
int buttonStateOld = HIGH;
// Create and bind the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
// Serial.begin(115200);
Serial.begin(31250); //Standard-Baudrate für MIDI-Signale
Serial.println("One Button Example with polling.");
// enable the standard led on pin 10-13.
pinMode(PIN_LED_RED, OUTPUT); // sets the digital pin as output
pinMode(PIN_LED_GREEN, OUTPUT); // sets the digital pin as output
pinMode(PIN_LED_BLUE, OUTPUT); // sets the digital pin as output
// enable the standard led on pin 10-13.
digitalWrite(PIN_LED_RED, ledState);
digitalWrite(PIN_LED_GREEN, ledState);
digitalWrite(PIN_LED_BLUE, ledState);
digitalWrite(PIN_LED_2, ledState);
//addition button for ON/OFF LED_RED
pinMode(PIN_INPUT2, INPUT_PULLUP); // Taster 2 ON/OFF
// link the click function to be called on a click event.
button.attachClick(Click);
button.attachDoubleClick(doubleClick);
button.attachLongPressStart(longClick);
}
void loop() {
// keep watching the push button:
button.tick();
// You can implement other code in here or just wait a while
buttonState = digitalRead(PIN_INPUT2);
if (buttonState == HIGH && buttonStateOld == LOW) {
Serial.println("Taster OFF");
digitalWrite(PIN_LED_2, LOW);
// Send note 42 with velocity 0 on channel 1
MIDI.sendNoteOn(42, 0, 1);
buttonStateOld = buttonState;
}
if (buttonState == LOW && buttonStateOld == HIGH) {
Serial.println("Taster ON");
digitalWrite(PIN_LED_2, HIGH);
// Send note 42 with velocity 127 on channel 1
MIDI.sendNoteOn(42, 127, 1);
buttonStateOld = buttonState;
}
delay(10);
}
// this function will be called when the button was pressed 1 times.
void Click()
{
Serial.println("x1");
ledState = !ledState; // reverse the LED
digitalWrite(PIN_LED_RED, ledState);
} // doubleClick
// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleClick()
{
Serial.println("x2");
ledState = !ledState; // reverse the LED
digitalWrite(PIN_LED_GREEN, ledState);
} // doubleClick
// this function will be called when the button was pressed for long timeframe.
void longClick()
{
Serial.println("long");
ledState = !ledState; // reverse the LED
digitalWrite(PIN_LED_BLUE, ledState);
} // doubleClick