Sunday, August 02, 2009

Five servos on the Make Controller Application Board

So can you run five servos on the Make Controller Application board? Yes, four of the "normal" servo connections and one (and possibly more) on the PWM outputs. Here is an example of five servos:


// five servos.c
// created Aug 1, 2009

#include "config.h"
#include "appled.h"
#include "pwmout.h"
#include "servo.h"


void UDPTask( void* p );
void Blink(void* p);
struct netconn* udpSocket;

void Run( ) // this task gets called as soon as we boot up.
{
AppLed_SetActive(0, 1); // enable LED 0
PwmOut_SetActive(0, 1); // between digital outs 0,1
Servo_SetActive(0,1);
Servo_SetActive(1,1);
Servo_SetActive(2,1);
Servo_SetActive(3,1);

Servo_SetSpeed(0,1023);
Servo_SetSpeed(1,1023);
Servo_SetSpeed(2,1023);
Servo_SetSpeed(3,1023);
PwmOut_SetDividerAValue(64); // servo limits duty 25 to 110
TaskCreate( Blink, "Blink", 1000, 0, 1 );
}


void Blink(void* p)
{
(void)p;
int i=25;

Led_SetState(1);
Sleep(1000);
while(1)
{
Led_SetState(0);
Sleep(100);
Led_SetState(1);
Sleep(100);
Servo_SetPosition(0,(i % 85)*12);
Servo_SetPosition(1,((i+20) % 85)*12);
Servo_SetPosition(2,((i+40) % 85)*12);
Servo_SetPosition(3,((i+60) % 85)*12);
PwmOut_SetDuty(0,i);
i++;
if(i>110){
i=25;
}
}
}

No comments: