Wednesday, February 8, 2012

Making the Trundle go forward

This is the code so far developed, not very complex yet but I have managed to make two continuous servos run in opposite directions and, so, to 'trundle' along.


// Trundle 1
// by codfangler
// This code is in the public domain.

#include <Servo.h>
Servo myservol;   // create servol object to control left servo
Servo myservor;  // create servor object to control right servo
                             
int posl = 0;       // variable to store the servol position
int posr = 180;  // variable to store the servor position

void setup()
{
  myservol.attach(9);     // attaches the servol on pin 9 to the servol object
  myservor.attach(10);  // attaches the servor on pin 10 to the servor object
}

void loop()
{
  for(posl = 0; posl < 180; posl += 1)    // goes from 0 degrees to 180 degrees
  for(posr = 180; posr < 0; posr += 1)  // goes from 180 degrees to 0 degrees
                                                            // in steps of 1 degree
{                                
    myservol.write(posl);              // tell servol to go to position in variable 'posl'
    delay(15);                              // waits 15ms for the servo to reach the position
}
{  
    myservor.write(posr);              // tell servor to go to position in variable 'posr'
    delay(15);                               // waits 15ms for the servo to reach the position
}
}
As the acrylic tube arrived simply to check sizes
After cutting to size and adding slots for wire




Simpler wiring by using a motor shield with  two servo outputs

No comments:

Post a Comment

Please add your comments here. We check most days and all suitable comments will be published.

Kardoma:

fills the stage with flags!
Free counters!