Can someone help me out with sample code for the common Tower Pro SG90 servo?
I’m able to get the servo to move briefly when I plug this in:
`// April controlling a servo with PWM
// Configure hardware
// the servo used in this example have ~170 degrees of range. Each servo has three pins: power, ground, and pulse in
// The width of the pulse determines the position of the servo
// The servo expects a pulse every 20 to 30 ms
// 0.8 ms pulse -> fully counterclockwise
// 2.6 ms pulse -> fully clockwise
// set up PWM on both pins at a period of 20 ms, and initialize the duty cycle
hardware.pin7.configure(PWM_OUT, 0.5, 0.018);
server.log("Hardware Configured");
class servo extends InputPort
{
name = "servo position"
type = "number"
function set(value) {
hardware.pin7.write(0.04 + (value * 0.09));
//server.log(format("%s set to %.2f", name, value));
}
}`
I have to play with the values in the first line after PWM_OUT to get it to move.
I want the servo to move to a known 90 degree position when a button is pushed on a webpage (via agent code) and then slowly return -90 degrees to a reset position. If the user presses the button while it is returning, it will move to that same 90 degree position again (not 90+ current location). Does this make sense?
For starters I just need to get the servo moving properly.
Thanks,
John