http://thenorthwestenterprise.com/wp-content/uploads/2020/06/BTcontrol.JPG

 

So I got a request from someone for a compact bluetooth controller to control an app called ONSONG.

I don’t use that app, but the OnSong people were good enough to add me to the Beta team for testing.

The app is pretty flexible and programable, so Isimply had each switch send a CC on/off when pressed. CC#17 and 18 specifically

 

I used:

ARDUINO NANO 33 iOT    $18.40

From BLMS:

a 1590A   – $4.99

2 switches $2.09 ea

a power jack $0.75

a single LED  $1.15 – indicates bluetooth connected

( I would have used 2 if it was for me, but he only wanted 1)

 

Total Parts, around $30

 

I wont go over the build, it was VERY basic- just

2 switches on Digital pins 5 and 9.

LED to pin 13.

If I had added an additional power LED that would go to 3.3v

VIN power and ground to power jack.

 

THE CODE:

 

//Bluetooth Page Turner for OnSong or other supported app
//by Cameron Newell @the.nw.enterprise, http://thenorthwestenterprise.com/
//Built for Ardruino NANO EVERY
//Some code stolen from Tom Igoe

#include <ArduinoBLE.h>

byte midiData[] = {0x80, 0x80, 0x00, 0x00, 0x00};


// previous state of the button:
int lastButtonState5 = LOW;
int lastButtonState9 = LOW;


// set up the MIDI service and MIDI message characteristic:
BLEService midiService("03B80E5A-EDE8-4B33-A751-6CE34EC4C700");
BLECharacteristic midiCharacteristic("7772E5DB-3868-4112-A1A9-F2669D106BF3",
                                     BLEWrite | BLEWriteWithoutResponse |
                                     BLENotify | BLERead, sizeof(midiData));


void setup() {
  // initialize serial communication
  Serial.begin(9600);
  pinMode(5, INPUT_PULLUP);
  // initialize built in LED:
  pinMode(LED_BUILTIN, OUTPUT);
  // Initialize BLE:
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");
    while (true);
  }
  // set local name and advertised service for BLE:
  BLE.setLocalName("Page_Turner");
  BLE.setAdvertisedService(midiService);

  // add the characteristic and service:
  midiService.addCharacteristic(midiCharacteristic);
  BLE.addService(midiService);

  // start advertising
  BLE.advertise();
}

void loop() {
  // wait for a BLE central
  BLEDevice central = BLE.central();

  // if a central is connected to the peripheral:
  if (central) {
    // turn on LED to indicate connection:
    digitalWrite(LED_BUILTIN, HIGH);
    while (central.connected()) {

      // read pushbutton5:
      int buttonState5 = digitalRead(5);
      Serial.println(buttonState5);
      // compare its state to the previous state:
      if (buttonState5 != lastButtonState5) {
        // debounce delay:
        delay(5);
        // if the button's changed and it's pressed:
        if (buttonState5 == LOW) {
          // send command
          midiCommand(0xB0, 0x11, 0x7F);
        } else  {
          // turn the note off:
          midiCommand(0xB0, 0x11, 0x00);
        }
        // save the button state for comparison next time through:
        lastButtonState5 = buttonState5;
      }

            // read pushbutton9:
      int buttonState9 = digitalRead(9);
      Serial.println(buttonState5);
      // compare its state to the previous state:
      if (buttonState9 != lastButtonState9) {
        // debounce delay:
        delay(5);
        // if the button's changed and it's pressed:
        if (buttonState9 == LOW) {
          // send command
          midiCommand(0xB0, 0x12, 0x7F);
        } else  {
          // turn the note off:
          midiCommand(0xB0, 0x12, 0x00);
        }
        // save the button state for comparison next time through:
        lastButtonState9 = buttonState9;
      }
    }
  }
  // when the central disconnects, turn off the LED:
  digitalWrite(LED_BUILTIN, LOW);

}

// send a 3-byte midi message
void midiCommand(byte cmd, byte data1, byte  data2) {
  // MIDI data goes in the last three bytes of the midiData array:
  midiData[2] = cmd;
  midiData[3] = data1;
  midiData[4] = data2;

  midiCharacteristic.setValue(midiData, sizeof(midiData));
}