Bluetooth Serial Connect Docs
Sketch API

The Arduino API is a read/update loop

Create a BluetoothSerialConnect instance, call readSerial() every loop, read the controls that changed, and send readout updates when your device state changes.

Use the API by job

JobUseMethod pattern
Open the BLE serial portIn setup()BluetoothSerialConnect serialConnect(Serial1, true)
serialConnect.begin(9600)
Refresh all inputsFirst line of loop()serialConnect.readSerial()
React to eventsWhen you only need a changewasButtonPressed(), wasToggleUpdated(), isSliderUpdated()
Read held stateWhen the current value mattersisButtonPressed(), isToggleOn(), getJoystick(), getSlider()
Update the appWhen the device has something to showsetDisplay(), setLabel(), setIndicator(), setGauge(), sendAlert()
The normal loop
void loop() {
  serialConnect.readSerial();

  if (serialConnect.wasButtonPressed(0)) {
    serialConnect.sendAlert("Button 0 pressed");
  }

  if (serialConnect.isSliderUpdated(0)) {
    analogWrite(9, (int)serialConnect.getSlider(0));
  }

  if (serialConnect.wasToggleUpdated(0)) {
    digitalWrite(2, serialConnect.isToggleOn(0) ? HIGH : LOW);
  }

  serialConnect.setGauge(analogRead(A0), 0);
}

BluetoothSerialConnect

BluetoothSerialConnect(HardwareSerial& serial, bool verbose = true)

Creates a parser and writer around the serial port connected to the BLE module.

Parameters
serial HardwareSerial&
Use Serial1, Serial2, or another hardware UART when the board provides one.
verbose bool
When true, received lines are echoed to the Arduino Serial monitor.
void begin(int baudRate = 9600)

Starts the BLE module serial port.

Parameters
baudRate int
Must match the UART baud configured on the BLE module.
void readSerial()

Reads all available input without blocking and refreshes every control's state.

Note: Call this near the start of every loop. It clears per-cycle event flags before parsing new input; held states (buttons, toggles, slider/joystick values) persist.

void setProtocol(BluetoothSerialConnectProtocol mode) / BluetoothSerialConnectProtocol protocol()

Selects the wire protocol. Defaults to BluetoothSerialConnectModern, matching the current app.

Note: Use BluetoothSerialConnectLegacy only when pairing with an older app version that sends the original B{n} / J{n} / @ / # format.

bool wasButtonPressed(int ch) / wasButtonReleased(int ch) / wasButtonRepeated(int ch)

Reports a button's down, up, and repeat events for the current read cycle.

Returns: true the cycle that event arrived.

bool isButtonPressed(int ch)

Returns whether a button is currently held down.

Returns: true between the down and up events (in modern mode).

bool isJoystickUpdated(int ch)

Returns whether a joystick reported a new position this read cycle.

Returns: true when readSerial() parsed a joystick message for that channel.

BluetoothSerialConnectJoystick getJoystick(int ch)

Returns the latest rotation and magnitude for a joystick channel.

Returns: A BluetoothSerialConnectJoystick value (see below). Invalid channels return a zeroed joystick.

bool isSliderUpdated(int ch) / double getSlider(int ch)

Reports a new slider value and returns the latest value.

Returns: getSlider() returns the value within the slider's configured range.

bool isToggleOn(int ch) / bool wasToggleUpdated(int ch)

Reads a latching toggle's state and whether it changed this cycle.

Returns: isToggleOn() persists; wasToggleUpdated() is true only on the change.

bool isDpadPressed(int ch, BluetoothSerialConnectDpadDirection dir)

Returns whether a D-Pad direction is held or was pressed this cycle.

Parameters
dir BluetoothSerialConnectDpadDirection
BluetoothSerialConnectDpadUp / Down / Left / Right / UpLeft / UpRight / DownLeft / DownRight / Center.
bool wasDpadPressed(int ch, dir) / wasDpadReleased(int ch, dir) / wasDpadRepeated(int ch, dir)

Reports a D-Pad direction's down, up, and repeat events for the current cycle.

Returns: true the cycle that direction event arrived.

bool hasMessage() / String getMessage()

Reads text the app sent through its console.

Note: getMessage() returns the latest console text and clears the unread flag reported by hasMessage().

void setDisplay(const String& message, int ch)

Updates an LCD-style Text Display component in the app.

Parameters
message String
Text to show; newlines are escaped on the wire.
ch int
The display's channel from the board layout.
void setLabel(const String& message, int ch)

Updates a plain text Label component.

Note: Falls back to a display update in legacy mode.

void setIndicator(bool on, int ch)

Turns an Indicator LED component on or off.

void setGauge(double value, int ch, int decimalPlaces = 2)

Sets a Gauge component's value; the bar fills within the gauge's configured range.

Parameters
decimalPlaces int
Digits sent after the decimal point (default 2).
void sendAlert(const String& message)

Shows a transient alert pop-up in the app.

Parameters
message String
Keep it short; BLE writes are chunked.
void writeSerial(const String& message)

Writes raw text to the app without adding a verb, channel, or newline.

Note: Send a complete protocol line yourself if you want the app to parse it.

void clearBuffer()

Clears the current cycle's control events.

Note: readSerial() calls this automatically before reading new input.

BluetoothSerialConnectError lastError() / const char* lastErrorMessage() / void clearError()

Reports and clears parser and protocol-configuration problems.

setButtonPrefix(), setJoystickPrefix(), setInputSuffix(), setOutputSuffix(), …

Legacy-mode tuning of the prefixes/suffixes used by the original protocol.

Note: Only relevant after setProtocol(BluetoothSerialConnectLegacy). The modern protocol is fixed and needs none of these.

BluetoothSerialConnectJoystick

BluetoothSerialConnectJoystick()

Creates an empty joystick value with rotation 0 and magnitude 0.

BluetoothSerialConnectJoystick(double rot, double mag)

Creates a joystick value from degrees and magnitude.

void updateValues(double rot, double mag)

Replaces the stored rotation and magnitude.

double getX()

Returns cos(rotation) multiplied by magnitude.

Returns: A value from -1.0 to 1.0 (right is positive).

double getY()

Returns sin(rotation) multiplied by magnitude.

Returns: A value from -1.0 to 1.0 (up is positive).

double getRotationDeg(double offset = 0)

Returns normalized joystick rotation in degrees.

Returns: A 0 to 360 degree value after subtracting the offset.

double getRotationRad(double offset = 0)

Returns normalized joystick rotation in radians.

Returns: A 0 to 2*PI value after subtracting the offset.

double getMagnitude()

Returns the distance from center.

Returns: 0.000 to 1.000.