Skip to content

Instantly share code, notes, and snippets.

@winhtut
Created March 19, 2020 12:24
Show Gist options
  • Save winhtut/0c53e46df0dc211400b05c719421f6c0 to your computer and use it in GitHub Desktop.
Save winhtut/0c53e46df0dc211400b05c719421f6c0 to your computer and use it in GitHub Desktop.
BluetoothAndCarManyServo
#include<Servo.h>
#include<SoftwareSerial.h>
SoftwareSerial bt(6,7);
Servo myServo;
Servo myServo1;
void setup() {
Serial.begin(9600);
bt.begin(9600);
myServo.attach(9);
myServo1.attach(10);
myServo.write(0);
myServo1.write(0);
}
void loop() {
if(bt.available()){
String val=bt.readString();
int value= val.toInt();
if( value>=0 && value=<180){
int myservo=map(value , 0 ,180 ,0,180);
Serial.println("controlling to myServo");
Serial.println(myservo);
myServo.write(myservo);
}
if(value >=180 && value=<360){
value=value-180;
int myservo=map(value , 0 ,180 ,0,180);
myServo1.write(myservo);
Serial.println("controlling to myServo1");
Serial.println(myservo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment