Hi
I am using a Dabble application on my iPhone UNO R4 Wifi has built-in Bluetooth Have tried a looked in many places but no luck pls help.
I like to make it move forward and back right and left,
On top of that when I finished another two Dc motors on the same H bridge and 2 servo on PCA9685k go back
Ideally, I like to
assign DC motors 1 and 2 is to go forward and back and right so you can assign the 4 arrows to it
DC Motor 3 and 4 need to go forward and back,
Assign dc 3 to square and forward arrow to go forward and square and backwards arrow to go back
Assign DC 4 to the x button and forward arrow to go forward and c button and backwards arrow to go back
assign servo 1 to the triangle and the forward arrow to go forward and the triangle plus backwards arrow to go back
assign servo 2 to the circle and forward arrow to go forward and circle plus backwards arrow to go back
On top of that when I finished another two Dc motors on the same H bridge and 2 servo on PCA9685k go back
#include "Arduino_LED_Matrix.h"
#include <ArduinoBLE.h>
#include <Servo.h>
// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3;
int in3 = 5;
int in4 = 4;
// For the LED Matrix
ArduinoLEDMatrix matrix;
const uint32_t happy[] = {
0x19819,
0x80000001,
0x81f8000
};
const uint32_t heart[] = {
0x3184a444,
0x44042081,
0x100a0040
};
// For the Servo
Servo myServo;
int prevAngle = -1;
// UUIDs for BLE service and characteristics
const char* deviceServiceUuid = "19b10000-e8f2-537e-4f6c-d104768a1214";
const char* deviceServiceRequestCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1215";
const char* deviceServiceResponseCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1216";
BLEService servoService(deviceServiceUuid);
BLEStringCharacteristic servoRequestCharacteristic(deviceServiceRequestCharacteristicUuid, BLEWrite, 4);
BLEStringCharacteristic servoResponseCharacteristic(deviceServiceResponseCharacteristicUuid, BLENotify, 4);
void mainDCcontrol();
void setup() {
// Initialize Serial
Serial.begin(9600);
// Initialize the LED Matrix
matrix.begin();
// Initialize the Servo
myServo.attach(9);
// Initialize BLE
BLE.begin();
BLE.setDeviceName("OCOne");
BLE.setLocalName("OCOne");
BLE.setAdvertisedService(servoService);
servoService.addCharacteristic(servoRequestCharacteristic);
servoService.addCharacteristic(servoResponseCharacteristic);
BLE.addService(servoService);
servoResponseCharacteristic.writeValue("0");
BLE.advertise();
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
// Handle BLE connections
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
while (central.connected()) {
if (servoRequestCharacteristic.written()) {
String newAngleStr = servoRequestCharacteristic.value();
int newAngle = newAngleStr.toInt();
if (prevAngle != newAngle) {
myServo.write(newAngle);
prevAngle = newAngle;
servoResponseCharacteristic.setValue(newAngleStr);
}
}
}
Serial.println("Disconnected from central");
}
mainDCcontrol();
// Display patterns on the LED matrix
matrix.loadFrame(happy);
delay(500);
matrix.loadFrame(heart);
delay(500);
}
void mainDCcontrol() {
directionControl();
delay(1000);
speedControl();
delay(1000);
}
// This function lets you control spinning direction of motors
void directionControl() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, 255);
analogWrite(enB, 255);
// Turn on motor A & B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(2000);
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
// Turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
// This function lets you control speed of the motors
void speedControl() {
// Turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Accelerate from zero to maximum speed
for (int i = 0; i < 256; i++) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Decelerate from maximum speed to zero
for (int i = 255; i >= 0; --i) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}









