Skip to content

Instantly share code, notes, and snippets.

@jerog1
Created March 25, 2014 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerog1/9754544 to your computer and use it in GitHub Desktop.
Save jerog1/9754544 to your computer and use it in GitHub Desktop.
ball-mover Arduino
#include <Servo.h>
Servo servo1; Servo servo2;
void setup() {
pinMode(1,OUTPUT);
servo1.attach(9); //analog pin 0
//servo1.setMaximumPulse(2000);
//servo1.setMinimumPulse(700);
servo2.attach(15); //analog pin 1
Serial.begin(19200);
Serial.println("Ready");
}
void loop() {
static int v = 0;
if ( Serial.available()) {
char ch = Serial.read();
switch(ch) {
case '0'...'9':
v = v * 10 + ch - '0';
break;
case 's':
servo1.write(v);
v = 0;
break;
case 'w':
servo2.write(v);
v = 0;
break;
case 'd':
servo2.detach();
break;
case 'a':
servo2.attach(15);
break;
}
}
// Servo::refresh();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment