Created
December 7, 2014 14:22
-
-
Save jacobrosenthal/67035493e0e3bd708fd4 to your computer and use it in GitHub Desktop.
Light Blue Bean Slider Control 2 Servos
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
#define LEFT 0 | |
#define RIGHT 2 | |
int leftServoPin = 0; | |
int rightServoPin = 1; | |
void setup(){ | |
pinMode(leftServoPin, OUTPUT); | |
pinMode(rightServoPin, OUTPUT); | |
} | |
void loop(){ | |
// Get any serial input from sandbox IOS app | |
char buffer[64]; | |
size_t length = 64; | |
length = Serial.readBytes(buffer, length); | |
if ( length > 0 ) | |
{ | |
for (int i = 0; i < length - 1; i += 2 ) | |
{ | |
if ( buffer[i] == LEFT ) | |
{ | |
analogWrite(leftServoPin, buffer[i+1]); | |
} | |
else if ( buffer[i] == RIGHT ) | |
{ | |
analogWrite(rightServoPin, buffer[i+1]); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment