Created
March 25, 2016 19:29
-
-
Save emil01/9a89800e383ec7f95b3f to your computer and use it in GitHub Desktop.
This file contains 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 <SoftwareSerial.h> | |
#include <Servo.h> | |
Servo myservo1, myservo2, myservo3; | |
void setup() | |
{ | |
myservo1.attach(9); | |
myservo2.attach(10); | |
myservo3.attach(11); | |
//Setup usb serial connection to computer | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
//Read from bluetooth and write to usb serial | |
if (Serial.available() >= 2 ) | |
{ | |
unsigned int servopos = Serial.read(); | |
unsigned int servopos1 = Serial.read(); | |
unsigned int realservo = (servopos1 * 256) + servopos; | |
Serial.println(realservo); | |
if (realservo >= 1000 && realservo < 1360) { | |
int servo1 = realservo; | |
servo1 = map(servo1, 1000, 1360, 0, 360); | |
myservo1.write(servo1); | |
Serial.println("servo 1 ON"); | |
delay(10); | |
} | |
if (realservo >= 1000 && realservo < 1360) { | |
int servo2 = realservo; | |
servo2 = map(servo2, 1000, 1360, 0, 360); | |
myservo2.write(servo2); | |
Serial.println("servo 2 On"); | |
delay(10); | |
} | |
if (realservo >= 1000 && realservo < 1360) { | |
int servo3 = realservo; | |
servo3 = map(servo3, 1000, 1360, 0, 360); | |
myservo3.write(servo3); | |
Serial.println("servo 3 On"); | |
delay(10); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment