Hi,
I am cotrolling VEX Robotics Motor using Arduino 101.
While the code works, I am only able to run one motor successfully.
When I try two motors, only one moves.
Can some one try to see what I might be doing wrong?
This is my code:
#include <CurieBLE.h>
#include <Servo.h>
Servo M1;
Servo M2;
#define motorOne 8
#define motorTwo 10
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming)
BLEService ControlMotor("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE AnalogRead Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedIntCharacteristic MotorStatus("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite );
int incom = 0;
int last_incom = 0;
void setup() {
Serial.begin(9600);
blePeripheral.setLocalName("ControlMotor");
blePeripheral.setAdvertisedServiceUuid(ControlMotor.uuid());
// add service and characteristic:
blePeripheral.addAttribute(ControlMotor);
blePeripheral.addAttribute(MotorStatus);
blePeripheral.begin();
pinMode(motorOne, OUTPUT);
pinMode(motorTwo, OUTPUT);
}
void loop() {
M1.attach(motorOne);
M2.attach(motorTwo);
BLECentral central = blePeripheral.central();
if (central) {
while (central.connected()) {
if (MotorStatus.written())
{
incom = MotorStatus.value();
if (incom != last_incom)
{
if (incom == 65)
{
M1.write(140); // THIS MOTOR MOVES
M2.write(140); // THIS MOTOR DOES NOT MOVE
}
}
last_incom = incom;
}
}
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}