Last active
March 25, 2017 08:17
-
-
Save tilosp/9a3c57fb661bd3b00b380a6901ad9d37 to your computer and use it in GitHub Desktop.
Receiver Sketch for Arduino Robot
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 <Servo.h> | |
const int leftServoPin = 10; | |
const int rightServoPin = 11; | |
Servo leftServo; | |
Servo rightServo; | |
byte inByte = 0; | |
void setup() { | |
Serial.begin(9600); | |
leftServo.attach(leftServoPin); | |
rightServo.attach(rightServoPin); | |
} | |
void loop() { | |
if (Serial.available() >= 2) { | |
inByte = Serial.read(); | |
switch (inByte) { | |
case 200: | |
inByte = Serial.read(); | |
if (inByte <= 180) | |
leftServo.write(inByte); | |
break; | |
case 201: | |
inByte = Serial.read(); | |
if (inByte <= 180) | |
rightServo.write(inByte); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment