|
|
View previous topic :: View next topic |
Author |
Message |
the_nes@hotmail.com Guest
|
Servos.c |
Posted: Tue Dec 04, 2007 2:13 pm |
|
|
here is an example for Servos.c Library, I named it as Servo Server
NOTE: u can control a delay, sending parameters from other pic
///////////////////// SServo.c /////////////////////
Code: |
#include "C:\Program Files\PICC\Projects\SServo\SServo.h"
#include <servos.c>
int1 side; //side { LEFT , RIGHT }
int8 speed; //speed { 0, 1, 2, 3, 4 }
int1 servo; //servo { servo 1, servo 2 }
void main()
{
init_servos(); //initialize servos
while(1) // RUN ALWAYS
{
speed = 0;
if(pin_B0) //if pin_B0 = 0, Servos on
{
if(pin_B4) {speed += 4;}
if(pin_B3) {speed += 2;} // pinB4, pinB3, pin_b2 determine the speed, 0b_ _ _
if(pin_B2) {speed += 1;}
if(pin_B1) {side = 1;}
else {side = 0;} // pin_B1, determine the direction, LEFT or RIGHT
if(pin_B5) {servo = 1;}
else {servo = 0;} // pin_B5, pin out, B7 or B6
set_servo(servo, side, speed); //send instruction to servo
}
else
{
stop_servos(); //if pin_B0 = 0, Servos off
}
}
}
|
//////////// SServo.h /////////////////////
Code: |
#include <16F874A.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(CLOCK = 4000000)
|
|
|
|
the_nes@hotmail.com Guest
|
|
Posted: Tue Dec 04, 2007 4:07 pm |
|
|
sorry
Code: |
#include "C:\Program Files\PICC\Projects\SServo\SServo.h"
#include <servos.c>
int1 side; //side { LEFT , RIGHT }
int8 speed; //speed { 0, 1, 2, 3, 4 }
int1 servo; //servo { servo 1, servo 2 }
void main()
{
set_tris_b(0b00111111);
init_servos(); //initialize servos
while(1) // RUN ALWAYS
{
speed = 0;
if(pin_B0) //if pin_B0 = 0, Servos on
{
if(input(pin_B4)) {speed += 4;}
if(input(pin_B3)) {speed += 2;} // pinB4, pinB3, pin_b2 determine the speed, 0b_ _ _
if(input(pin_B2)) {speed += 1;}
if(input(pin_B1)) {side = 1;}
else {side = 0;} // pin_B1, determine the direction, LEFT or RIGHT
if(input(pin_B5)) {servo = 1;}
else {servo = 0;} // pin_B5, pin out, B7 or B6
set_servo(servo, side, speed); //send instruction to servo
delay_ms(500);
}
else
{
stop_servos(); //if pin_B0 = 0, Servos off
}
}
}
|
|
|
|
the_nes@hotmail.com Guest
|
ss |
Posted: Tue Dec 04, 2007 4:08 pm |
|
|
Code: |
#include "C:\Program Files\PICC\Projects\SServo\SServo.h"
#include <servos.c>
int1 side; //side { LEFT , RIGHT }
int8 speed; //speed { 0, 1, 2, 3, 4 }
int1 servo; //servo { servo 1, servo 2 }
void main()
{
set_tris_b(0b00111111);
init_servos(); //initialize servos
while(1) // RUN ALWAYS
{
speed = 0;
if(input(pin_B0)) //if pin_B0 = 0, Servos on
{
if(input(pin_B4)) {speed += 4;}
if(input(pin_B3)) {speed += 2;} // pinB4, pinB3, pin_b2 determine the speed, 0b_ _ _
if(input(pin_B2)) {speed += 1;}
if(input(pin_B1)) {side = 1;}
else {side = 0;} // pin_B1, determine the direction, LEFT or RIGHT
if(input(pin_B5)) {servo = 1;}
else {servo = 0;} // pin_B5, pin out, B7 or B6
set_servo(servo, side, speed); //send instruction to servo
delay_ms(500);
}
else
{
stop_servos(); //if pin_B0 = 0, Servos off
}
}
}
|
|
|
|
arawana
Joined: 06 Apr 2008 Posts: 19 Location: SINGAPORE
|
|
Posted: Mon Jun 23, 2008 4:04 am |
|
|
hi..
i want to ask u a question please...
about servo.c library... which 2 pins i have connect to give signal to my 2 servos and i am using PIC16f877a 20Mhz..
and if i want to control more than 2 servo with speed control, can i use this servo.c library? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
davemaster2000
Joined: 18 Dec 2005 Posts: 2 Location: Peru
|
|
Posted: Thu Jul 28, 2011 10:43 am |
|
|
arawana wrote: | hi..
i want to ask u a question please...
about servo.c library... which 2 pins i have connect to give signal to my 2 servos and i am using PIC16f877a 20Mhz..
and if i want to control more than 2 servo with speed control, can i use this servo.c library? |
Greetings,
As default in servos.c file, you have the following:
#ifndef LEFT_SERVO_PIN
#define LEFT_SERVO_PIN PIN_D6
#define RIGHT_SERVO_PIN PIN_D7
#endif
But, you can change it in your code...
Best regards |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|