Forum >Example Code For Servos (multiple) on Romeo
RoboticsGeneral

Example Code For Servos (multiple) on Romeo

userHead mark.perino 2018-09-12 11:58:09 3647 Views1 Replies
Hello,
Finiding it very hard to locate example code for the ROMEO BLE mini using servo's. The wiki page:https://www.dfrobot.com/wiki/index.php/ ... KU:DFR0351

Has a good example of using the motor interface, but It would be very helpful to a similar example that controls 2 servos. Let's say servo on #2 responds to "a" and "d" as left right (im assuming degree positions of like 135, 75) and that servo #3 responds to "w" and "s" with up down.

Any examples would be greatly appreciated.
2018-09-14 09:10:34 I didnt get any response, but figured it out. The example code on:

https://www.dfrobot.com/wiki/index.php/ ... KU:DFR0100

Worked with the ROMEO BLE Mini. No special additional libraries, as Servo.h is standard in Arduino IDE.

here's my example code to move 2 servos connected to Digital ports 2 & 3:
Code: Select all
// Moving two Servos on ROMEO BLE mini
// This example code is in the public domain.
// This code will move 2 servos from 0->180 degrees, then 180->0 degrees,
// then wait 10 seconds. It is an endless loop. Make sure your servos
// can move 0-180.
#include <Servo.h>
Servo myserone; // create servo object to control the first servo
Servo mysertwo; // create a second servo object
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int serone = 2; // first servo board location
int sertwo = 3; // second servo location
void setup() {
myserone.attach(serone); // attaches the servo on pin defined by serone
mysertwo.attach(sertwo); // attach to servo 2
}
void loop() {
for(pos =0; pos <180; pos+=1){
myserone.write(pos);
mysertwo.write(pos);
delay(15);
}
for(pos = 180; pos >=1; pos-=1){
myserone.write(pos);
mysertwo.write(pos);
delay(15);
}
delay(10000);
}
userHeadPic mark.perino