Servo.attach

From Pinguino
Jump to: navigation, search

Name

servo.attach

Description

This function defines a Pinguino pin as servo driver.

It allows to define any user pin. For pin ranges available visit: [Servo library supported boards ]

Since
Beta 9.
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

void servo.attach(u8 pin);
pin 
Value: Check valid values according to board : [Servo library supported boards ]
Argument type: unsigned byte
Output
None

Example

The following example defines pin 13 as servo driver.

In the loop() it's defined a variation of servo position every half second.

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
//   |     | 
//   +-----+
// This routine is valid for pinguino boards: 
// Generic 2550 (no #define needed)
// Generic 4550 (enable #define PIC18F4550),
// PICUNO EQUO (enable #define PICUNO_EQUO)

uchar position=1;

void setup(void)
{
servo.attach(13);
servo.setMaximumPulse(13,2500);  // Maximum pulse width in microseconds (180 degrees).
servo.setMinimumPulse(13,500);   // Minimum pulse width in microseconds (0 degrees).
}

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

Bugs

See also

servo.detach

servo.write

servo.read

servo.setMaximumPulse

servo.setMinimumPulse

Comments