Servo.setMaximumPulse

From Pinguino
Jump to: navigation, search

Name

servo.setMaximumPulse

Description

This function sets the maximum pulse width allowed for the servo specified (That maximum pulse width commonly is equal to 180 degrees position).

Since
Beta 32X, releasee 323.
Warning!
Servo library uses PIC's Timer1 (TMR1). So, be aware of that in case you plan to use a timer in your application. Otherwise you could disrupt servo library.

Syntax

 servo.setMaximumPulse(pin,pulsewidth);
pin 
Value: Check valid values according to board : [Servo library supported boards ]
Argument type: unsigned char
pulsewidth 
value in microseconds, allowed values must be lower than 2500 microseconds.
Argument type: integer
Output
None

Example

The following example defines pin 8 as servo driver.

In the loop(), position of servo(pin 8) will be alternated from maximum to minimum positions every 2 seconds.

Connectivity diagram is shown within the code comments.

// 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
//   |     | 
//   +-----+


void setup(void)
{
servo.attach(8);
servo.setMaximumPulse(8,2200);
servo.setMinimumPulse(8,700);
}

//The following routine just alternate positions from 0 to 180 degrees every 2 seconds.
void loop(void)
{
delay(2000);
servo.write(8,180);
delay(2000);
servo.write(8,0);
}

Bugs

See also

servo.attach

servo.detach

servo.write

servo.read

servo.setMinimumPulse

Comments