Created
March 19, 2020 12:24
-
-
Save winhtut/0c53e46df0dc211400b05c719421f6c0 to your computer and use it in GitHub Desktop.
BluetoothAndCarManyServo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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