Files
processing4/java/libraries/io/examples/ServoSweep/ServoSweep.pde
gohai dbdeb9cf66 IO: We want motors, they said (implements SoftwareServo)
Some measurements with a logic analyzer and the Raspberry Pi 2
sleep: 0.001500, measured avg: 0.0015357, measured 0.95 perc.: 0.0015573
sleep: 0.0185, measured avg: 0.0186177, measured 0.95 perc.: 0.0186345

servo_pulse_oversleep was set to account for the (expected) overhead of waking up and toggling the pin with help from the numbers above.
2016-06-23 19:52:14 +02:00

35 lines
845 B
Plaintext

import processing.io.*;
// see setup.png in the sketch folder for wiring details
// for more reliable operation it is recommended to power
// the servo from an external power source, see setup_better.png
SoftwareServo servo1;
SoftwareServo servo2;
void setup() {
size(400, 300);
servo1 = new SoftwareServo(this);
servo1.attach(17);
servo2 = new SoftwareServo(this);
servo2.attach(4);
}
void draw() {
background(0);
stroke(255);
strokeWeight(3);
// we don't go right to the edge to prevent
// making the servo unhappy
float angle = 90 + sin(frameCount / 100.0)*85;
servo1.write(angle);
float y = map(angle, 0, 180, 0, height);
line(0, y, width/2, y);
angle = 90 + cos(frameCount / 100.0)*85;
servo2.write(90 + cos(frameCount / 100.0)*85);
y = map(angle, 0, 180, 0, height);
line(width/2, y, width, y);
}