Skip to content

Instantly share code, notes, and snippets.

@tilosp
Last active March 25, 2017 08:17
Show Gist options
  • Save tilosp/9a3c57fb661bd3b00b380a6901ad9d37 to your computer and use it in GitHub Desktop.
Save tilosp/9a3c57fb661bd3b00b380a6901ad9d37 to your computer and use it in GitHub Desktop.
Receiver Sketch for Arduino Robot
#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