(im editing this post questions since what i have wrote b4 was a completely mess to follow)
ok so yesterday b4 get any replay in here i just came up with what u just said about my servo motors; I was using continuous positional servo motor xd ... (respect with the diagram in thinkercard this circuit i made like 2 weeks ago and didnt know how much needed to power up so i just put that 2 AAA batteries as a reference that have to be powered with external power ik its wrong just changed after that because right now im not using that to power my circuit xd )
right now i cant really test if the new code that i modified yesterday is working or no but it present no error after compiling without saying more just gonna upload it
hopefully someone can tell me if something is wrong or have no sense in the code because in the end i modified by myself base of all the examples that i have seem related to this
what is what i want to do???
i wanna control 2 servo motors and one dc motor by bluetooth through the App Mit Inventor
so in the app ill have 2 slider for each servo and move any degree from 0 to 180
and with the dc motor 3 buttons Forward Backward and Stop
that's all
so this is the code:
#include <Servo.h>
Servo servo1;
Servo servo2;
char a;
String readString;
int Forwardmotor = 8; //pins in the arduino UNO
int Backwardmotor = 9;
int speed = 255; //(motor speed 0-255)
void setup() {
servo1.attach(5);
servo2.attach(6);
servo1.write(0); //initial servos position
servo2.write(90); // initial servos position
pinMode(Forwardmotor, OUTPUT);
pinMode(Backwardmotor, OUTPUT);
Serial.begin(9600);
delay(10);
}
void loop() {
if (Serial.available()) {
a = Serial.read();
if(a=='A'){
Servo1();
}
if(a=='B'){
Servo2();
}
if(a=='C'){ //motor move forward
analogWrite(Forwardmotor, speed);
analogWrite(Backwardmotor, 0);
}
if(a=='D'){ //motor move backward
analogWrite(Forwardmotor, 0);
analogWrite(Backwardmotor, speed);
}
if(a=='E'){ //motor stop
analogWrite(Forwardmotor, 0);
analogWrite(Backwardmotor,0);
}
}
}
void Servo1(){ //servo motor 1 //servo motor get slider thumbsposition
delay(10);
while (Serial.available()) {
char b = Serial.read();
readString += b;
}
if (readString.length() >0) {
Serial.println(readString.toInt());
servo1.write(readString.toInt());
readString=""; // Clear string
}
}
void Servo2(){ //servo motor 2 //servo motor get slider thumbsposition
delay(10);
while (Serial.available()) {
char b = Serial.read();
readString += b;
}
if (readString.length() >0) {
Serial.println(readString.toInt());
servo2.write(readString.toInt());
readString="";
}
}