Hello, I am working on a project which revolves around haptic systems. I have written a basic app which uses 9 buttons that needs to send text with the help of a HC-06 bluetooth device to my ardunio uno card that is connected with a pca9685 motor driver [ there are 9 servo motors that are bound to the pins (0,2,4,6,8,10,12,14,15)] that turns with the specific command], in the app there seems to be no error and sends the signal correctly to the arduino card, however when looked through the serial port screen it only shows the text which the app sent and doesn't turn the specified servo motor. How can I solve this issue?
(The code looks like this):
normally sketch is posted not as picture but as CODE by using CODE tags, so helpers able to copy sketch in one click.
edit your post.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 600
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(60);
}
void loop() {
if (Serial.available()) {
char command = Serial.read();
Serial.println(command);
int servoNum = command;
if (servoNum >= 0 && servoNum < 16) {
moveServo(servoNum,30);
delay(1000);
moveServo(servoNum,0);
}
}
}
void moveServo(int servoNum,int angle) {
int pulseLength = map(angle, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(servoNum, 0, pulseLength);
}
sorry, new to the site
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 1000
#define SERVOMAX 2000
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(60);
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
Serial.println(command);
byte servoNum = command - 48;
while (Serial.available() > 0)Serial.read();
if (servoNum >= 0 && servoNum < 16) {
moveServo(servoNum, 30);
delay(1000);
moveServo(servoNum, 0);
}
}
}
void moveServo(int servoNum, int angle) {
int pulseLength = map(angle, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(servoNum, 0, pulseLength);
}
thanks it runs perfectly now
mark post#7 as solution