This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
servo-interactive-test [2012/10/06 14:16] 85.218.109.130 created |
servo-interactive-test [2012/10/06 14:21] 85.218.109.130 |
||
---|---|---|---|
Line 2: | Line 2: | ||
<code java> | <code java> | ||
- | // Controlling a servo position using a potentiometer (variable resistor) | + | // Controlling a servo position using serial input |
- | // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> | + | |
#include <Servo.h> | #include <Servo.h> | ||
Line 29: | Line 28: | ||
int intdata = atoi(t); | int intdata = atoi(t); | ||
Serial.println(intdata); | Serial.println(intdata); | ||
- | myservo.write(intdata); | + | myservo.write(intdataser = serial.Serial("/dev/ttyACM0",9600)); |
str = String(); | str = String(); | ||
} | } | ||
Line 36: | Line 35: | ||
} | } | ||
} | } | ||
- | //else { | + | |
- | // for (val=0; val<179; val++) { | + | |
- | // myservo.write(val); // sets the servo position according to the scaled value | + | |
- | // delay(5); // waits for the servo to get there | + | |
- | // } | + | |
- | // for (val=179; val>0; val--) { | + | |
- | // myservo.write(val); | + | |
- | // delay(5); | + | |
- | // } | + | |
- | // } | + | |
} | } | ||
+ | </code> | ||
+ | |||
+ | then in python: | ||
+ | |||
+ | <code python> | ||
+ | import serial | ||
+ | ser=serial.Serial("/dev/ttyACM0", 9600) | ||
+ | ser.write(30) | ||
</code> | </code> |