Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- int incomingByte;
- Servo Xservo;
- Servo Yservo;
- int xpos = 0;
- int ypos = 0;
- void setup()
- {
- Serial.begin(9600);
- Xservo.attach(6);
- Yservo.attach(5);
- ypos = 90;
- xpos = 90;
- }
- void refresh(){
- Xservo.write(xpos);
- Yservo.write(ypos);
- }
- void loop()
- {
- refresh();
- if (Serial.available() > 0) {
- incomingByte = Serial.read();
- if (incomingByte == 'U') {
- ypos = ypos - 10;
- refresh();
- }
- if (incomingByte == 'D') {
- ypos = ypos + 10;
- refresh();
- }
- if (incomingByte == 'L') {
- xpos = xpos + 10;
- refresh();
- }
- if (incomingByte == 'R') {
- xpos = xpos - 10;
- refresh();
- }
- if (incomingByte == 'C') {
- xpos = 90;
- ypos = 90;
- refresh();
- }
- }
- }
Add Comment
Please, Sign In to add comment