Pages: [1]   Go Down
Author Topic: [LIB] ShiftOut + Servos  (Read 845 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have to say, its nothing too hard do what i did, but in actions is pretty cool  smiley-grin
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:



Lib attached on the topic.
This is an example:
Code:
#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);

}

* ShiftOutServo.rar (3.8 KB - downloaded 5 times.)
Logged

Pages: [1]   Go Up
Jump to: