Go Down

Topic: [LIB] ShiftOut + Servos (Read 911 times) previous topic - next topic

Mock

I have to say, its nothing too hard do what i did, but in actions is pretty cool  :D
I have taken the SoftwareServo lib  ( http://www.arduino.cc/playground/ComponentLib/servo ) edited a bit and it can control servos attached on a Shift register (http://arduino.cc/en/Tutorial/ShiftOut )

Tested on arduino IDE 0022

Video:

www.youtube.com/watch?v=Wg1CI0ii6Cg

Lib attached on the topic.
This is an example:
Code: [Select]

#include <ShiftOutServo.h> //Just including

#define latchPin  A0
#define clockPin  A2
#define dataPin  A1
//I am using analog pins vbut you can also use digitals...

byte pins[] = {latchPin,clockPin,dataPin};
bool originalData[] = {0,0,0,0,0,0,0,0}; //The [0] and [1] is for servos

ShiftOutServo servo1;
ShiftOutServo servo2;
void setup(){
        pinMode(latchPin, OUTPUT);
        pinMode(clockPin, OUTPUT);
        pinMode(dataPin, OUTPUT);
        servo1.attach(0);
        servo2.attach(1);
}

int the_angle = 0;
long int timett;
int adding = 2;
int bgn =  2;
void loop()
{
  servo1.write(the_angle);
  servo2.write(180-the_angle);
  //Shifting some leds...
  originalData[bgn] = 0;
  bgn++;
  if (bgn == 8){
      originalData[7] = 0;
      bgn = 2;
  }
  originalData[bgn] = 1;

  //Its nice do it to reduce noise...
  timett = millis()+10;
  while(timett >= millis()){
    ShiftOutServo::refresh(pins,originalData);
  }

  the_angle= the_angle+adding;
  if (the_angle >= 180 || the_angle <= 0 ) adding = adding*(-1);
  delay(10);

}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy