Servos Control Example

From Pinguino
Jump to: navigation, search


The following routine defines many Pinguino pins as servo drivers, and define for each a diferent maximum and minimum values for pulse widths. The routine modifies their values to demonstrate how all of them move at the same time, using functions servo.attach, servo.write, servo.setMaximumPulse and servo.setMinimumPulse.

// Servo library test with Pinguino
// Connect servo control lines to pinguino pins.
// Feed servos with +5 V:
//
//   +-----+
//   |servo|--------- PWM Servo control ---> to pinguino pin.
//   |     |--------- +5V
//   |  o  |--------- GND
//   |     | 
//   +-----+

unsigned char position=1;

setup()
{
servo.attach(0);
servo.setMaximumPulse(0,2500);
servo.setMinimumPulse(0,500);
servo.attach(1);
servo.setMaximumPulse(1,2500);
servo.setMinimumPulse(1,500);
servo.attach(2);
servo.setMaximumPulse(2,2200);
servo.setMinimumPulse(2,700);
servo.attach(3);
servo.setMaximumPulse(3,2200);
servo.setMinimumPulse(3,700);
servo.attach(4);
servo.setMaximumPulse(4,2200);
servo.setMinimumPulse(4,700);
servo.attach(5);
servo.setMaximumPulse(5,2200);
servo.setMinimumPulse(5,700);
servo.attach(6);
servo.setMaximumPulse(6,2000);
servo.setMinimumPulse(6,1000);
servo.attach(7);
servo.setMaximumPulse(7,2200);
servo.setMinimumPulse(7,700);
servo.attach(8);
servo.setMaximumPulse(8,2200);
servo.setMinimumPulse(8,700);
servo.attach(9);
servo.setMaximumPulse(9,2500);
servo.setMinimumPulse(9,500);
servo.attach(10);
servo.setMaximumPulse(10,2200);
servo.setMinimumPulse(10,700);
}

loop()
{                        
servo.write(0,180-position);
servo.write(1,180-position);
servo.write(2,180-position);
servo.write(3,180-position);
servo.write(4,180-position);
servo.write(5,position);
servo.write(6,position);
servo.write(7,position);
servo.write(8,position);
servo.write(9,position);
servo.write(10,position);
delay(250);
position++;
}