Servo.write

From Pinguino
Jump to: navigation, search

Name

servo.write

Description

This function sets a servo position to the degrees position specified by argument '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.write(pin,position);
pin 
Value: Check valid values according to board : [Servo library supported boards ]
Argument type: unsigned char
position
Valid values are from 0 to 180 degrees.
Argument type: unsigned char
Output
None

Example

The following example defines pin 15 as servo driver.

In the loop(), position of servo-pin 15 will be modified 1 degree every half second. Once reached 180 degrees position it will return to 0 degrees position.

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

uchar position=1;

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

void loop(void)
{
delay(500);
position++;
servo.write(15,position);
if(position>180) position=0;
}

Bugs

See also

servo.attach

servo.detach

servo.read

servo.setMaximumPulse

servo.setMinimumPulse

Comments