How create forward button with bluetooth low energy

Hi , i need help finish code for controller app for my rc car , last thing i need forward button
code arduino: void executeCommand(char cmd) {
switch (cmd) {
case 'F':
// Forward motion
digitalWrite(MOTOR_1A, HIGH);
digitalWrite(MOTOR_1B, LOW);
break;
case 'B':
// Backward motion
digitalWrite(MOTOR_1A, LOW);
digitalWrite(MOTOR_1B, HIGH);
break;
case 'L':
// Turn left
steeringServo.write(45);
break;
case 'R':
// Turn right
steeringServo.write(0);
break;
case 'S':
// Stop
digitalWrite(MOTOR_1A, LOW);
digitalWrite(MOTOR_1B, LOW);
break;
}
}
and here app code :

What services/characteristics are your Arduino code looking for? There isn't enough information on the microcontroller side to advise what the next steps are. Ultimately, depending on how you've structured your services and characteristics, and specifically how they end up invoking your executeCommand function, will inform the App Inventor side.

board i use arduino nano 2040 .
I want i click on app button f , and mit app inventor send char comand to arduino board to do comand ( go forward)
void executeCommand(char cmd) {
switch (cmd) {
case 'F':
// Forward motion
case 'L':
// Turn left
steeringServo.write(45);
break;
digitalWrite(MOTOR_1A, HIGH);
digitalWrite(MOTOR_1B, LOW);
break;
and second buton for turn

just buttons with ble for control car thought ble

Ok. But when it comes to communicating with a BLE device there is a bunch of overhead that you have to manage. Here's an example from the Arduino documentation that includes things like setting up a BLEService and BLEByteCharacteristic. Your code snippets show none of that, but it is critical to understanding what to write on the App Inventor side. Are you able to post the contents of your entire .ino file?

not now , but full code i copied already here from scatch .Im new in this thing , and i have almost zero clue what i doing


here is circluid of rc model

here full code :slight_smile:
#include <ArduinoBLE.h>
#include <Servo.h>

BLEService rcCarService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Define a custom service UUID
BLECharCharacteristic cmdCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLEWrite); // Define a custom characteristic UUID

#define SERVO_PIN 3

#define MOTOR_1A 7
#define MOTOR_1B 8

Servo steeringServo;

void executeCommand(char cmd);

void setup() {
Serial.begin(9600);

pinMode(SERVO_PIN, OUTPUT);

pinMode(MOTOR_1A, OUTPUT);
pinMode(MOTOR_1B, OUTPUT);

steeringServo.attach(SERVO_PIN);

while (!Serial) {
}

// Start BLE
if (!BLE.begin()) {
    Serial.println("failed to initialize BLE!");
    while (1) {
    }
}

BLE.setLocalName("RCCar");                          // set the local name peripheral advertises
BLE.setAdvertisedService(rcCarService);             // set the UUID for the service this peripheral advertises
rcCarService.addCharacteristic(cmdCharacteristic);  // add the characteristics to the service
BLE.addService(rcCarService);                       // add the service
BLE.advertise();                                    // start advertising
Serial.println("Bluetooth® device active, waiting for connections...");

}

void loop() {
// listen for Bluetooth® Low Energy peripherals to connect:
BLEDevice central = BLE.central();

// if a central is connected to peripheral:
if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
        // if the remote device wrote to the characteristic,
        // use the value to control the LED:
        if (cmdCharacteristic.written()) {
            executeCommand(cmdCharacteristic.value());
        }
    }

    // when the central disconnects, print it out:
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
}

}

void executeCommand(char cmd) {
switch (cmd) {
case 'F':
// Forward motion
digitalWrite(MOTOR_1A, HIGH);
digitalWrite(MOTOR_1B, LOW);
break;
case 'B':
// Backward motion
digitalWrite(MOTOR_1A, LOW);
digitalWrite(MOTOR_1B, HIGH);
break;
case 'L':
// Turn left
steeringServo.write(45);
break;
case 'R':
// Turn right
steeringServo.write(0);
break;
case 'S':
// Stop
digitalWrite(MOTOR_1A, LOW);
digitalWrite(MOTOR_1B, LOW);
break;
}
}

Based on that information, it seems like the WriteBytes block should do the trick, e.g.:

Thank you