Hello Hi and another Happy New Year in the round ...
I'm Robert from near Hanover and am a complete newcomer to Arduino & Co.
To be honest, I am also not a programmer and only became aware of Arduino because I am a guitarist and have seen that I can convert a foot controller with an Arduino.
THE FOLLOWING:
- I have a housing with 12x foot switches
- Each of these switches should send a simple Midi CC command to control the "BIAS FX" software
- I watched some videos and tutorials and finally came across Merwin's "MIDI_Guitar" project
- I then ordered an Adafruit Bluefruit LE and wired everything as he did it.
- I also installed the Sketsch and I managed to connect to my iPad via Bluetooth
- JAAA, I even have a great MIDI keyboard on the floor now
Because then I found that BIAS FX didn't want to send "notes", but CC's (ControlChanges)
I tried everything "me" possible but unfortunately my knowledge is far from sufficient.
I do not need a "bank" or "octave" switchover, just 12 fixed CC's that are sent to the iPad via the 12 buttons ...
for example like this:
Key 1 sends CC30 with a value of 127
Key 2 sends CC31 with a value of 127
etc etc
Please excuse me if a beginner should be able to do that, but I'm finished with my Latin and would be very grateful for a solution ...
Best wishes
This is the code using by Merwin:
/*
Video for this project here:https://youtu.be/QPgYpVHFSQY
Thank you for checking out my video and my code!
For more videos and information check out
https://www.youtube.com/merwinmusic
http://www.lukemerwin.com/
*/
#include <Arduino.h>
#include <SPI.h>
#if not defined (_VARIANT_ARDUINO_DUE_X_) && not defined (_VARIANT_ARDUINO_ZERO_)
#include <SoftwareSerial.h>
#endif
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "Adafruit_BLEMIDI.h"
#include "BluefruitConfig.h"
#define FACTORYRESET_ENABLE 0
#define MINIMUM_FIRMWARE_VERSION "0.7.0"
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
Adafruit_BLEMIDI midi(ble);
bool isConnected = false;
// A small helper
void error(const __FlashStringHelper*err) {
Serial.println(err);
while (1);
}
// callback
void connected(void)
{
isConnected = true;
Serial.println(F(" CONNECTED!"));
delay(1000);
}
void disconnected(void)
{
Serial.println("disconnected");
isConnected = false;
}
void BleMidiRX(uint16_t timestamp, uint8_t status, uint8_t byte1, uint8_t byte2)
{
Serial.print("[MIDI ");
Serial.print(timestamp);
Serial.print(" ] ");
Serial.print(status, HEX); Serial.print(" ");
Serial.print(byte1 , HEX); Serial.print(" ");
Serial.print(byte2 , HEX); Serial.print(" ");
Serial.println();
}
const int ButtonPins[12] = {2, 3, 5, 6, 9, 10, 11, 12, 13, 18, 19, 20};
int LastButtonState[12] = {0};
int currentMillis = 0;
int LastButtonChangeTime[12] = {currentMillis};
int NoteNumber[12] = {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35};
int buttonPushCounter = 0;
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Adafruit Bluefruit MIDI Example"));
Serial.println(F("---------------------------------------"));
/* Initialise the module */
Serial.print(F("Initialising the Bluefruit LE module: "));
if ( !ble.begin(VERBOSE_MODE) )
{
error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
}
Serial.println( F("OK!") );
if ( FACTORYRESET_ENABLE )
{
/* Perform a factory reset to make sure everything is in a known state */
Serial.println(F("Performing a factory reset: "));
if ( ! ble.factoryReset() ) {
error(F("Couldn't factory reset"));
}
}
//ble.sendCommandCheckOK(F("AT+uartflow=off"));
ble.echo(false);
Serial.println("Requesting Bluefruit info:");
/* Print Bluefruit information */
ble.info();
/* Set BLE callbacks */
ble.setConnectCallback(connected);
ble.setDisconnectCallback(disconnected);
// Set MIDI RX callback
midi.setRxCallback(BleMidiRX);
Serial.println(F("Enable MIDI: "));
if ( ! midi.begin(true) )
{
error(F("Could not enable MIDI"));
}
ble.verbose(false);
Serial.print(F("Waiting for a connection..."));
for(int i=0; i < 15; i++)
pinMode(ButtonPins[i],INPUT_PULLUP);
}
void loop() {
//-------------------------------------------------------------------------------------//
// interval for each scanning ~ 500ms (non blocking)
ble.update(250);
// bail if not connected
if (! isConnected)
return;
int octave = (buttonPushCounter * 12);
//-----------------------------------------------------------------------------------//
{
unsigned long currentMillis = millis();
for (int i=0; i<15; i++) {
boolean state = !digitalRead(ButtonPins[13]); // 'true'==pressed, 'false'==released
// Check for state change and do debounce
if (state != LastButtonState[13] && currentMillis-LastButtonChangeTime[13] > 50) {
LastButtonState[13] = state;
LastButtonChangeTime[13] = currentMillis;
if (state){
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
}
}
//-----------------------------------------------------------------------------------//
{
unsigned long currentMillis = millis();
for (int i=0; i<15; i++) {
boolean state = !digitalRead(ButtonPins[14]); // 'true'==pressed, 'false'==released
// Check for state change and do debounce
if (state != LastButtonState[14] && currentMillis-LastButtonChangeTime[14] > 50) {
LastButtonState[14] = state;
LastButtonChangeTime[14] = currentMillis;
if (state){
buttonPushCounter--;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
}
}
{
if (buttonPushCounter < -1){
buttonPushCounter = -1;
}
if (buttonPushCounter > 6){
buttonPushCounter = 6;
}
}
//-----------------------------------------------------------------------------------//
{
unsigned long currentMillis = millis();
for (int i=0; i<13; i++) {
boolean state = !digitalRead(ButtonPins[i]); // 'true'==pressed, 'false'==released
// Check for state change and do debounce
if (state != LastButtonState[i] && currentMillis-LastButtonChangeTime[i] > 50) {
LastButtonState[i] = state;
LastButtonChangeTime[i] = currentMillis;
if (state)
midi.send(0xB0, octave + NoteNumber[i], 127); // Pressed
else
midi.send(0xB0, octave + NoteNumber[i], 0); // Released
}
}
}
//-----------------------------------------------------------------------------------//
}