I tried to create a small turtle that would wave it’s little flippers. It did not exactly work as planned. Firstly, it became a more abstract idea of a turtle (a more futuristic interpretation). Although the laser cutting worked fine, the physical motion part was awkward and stunted. I believe that to create a better system for movement, I would need a gear system to allow it to work properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #define DIR_PIN 2 // The direction pin controls the direction of stepper motor rotation. #define STEP_PIN 3 // Each pulse on the STEP pin moves the stepper motor one angular unit. #define ENABLE_PIN 4 // Optional control of the driver power. void setup( void ) { pinMode(DIR_PIN, OUTPUT); pinMode(STEP_PIN, OUTPUT); pinMode(ENABLE_PIN, OUTPUT); digitalWrite(ENABLE_PIN, LOW); Serial.begin(9600); } void rotate_stepper( int steps, float speed) { // Configure the direction pin on the stepper motor driver based on the sign // of the displacement. int dir = (steps > 0)? HIGH:LOW; digitalWrite(DIR_PIN, dir); // Find the positive number of steps pulses to emit. int pulses = abs(steps); // Compute a delay time in microseconds controlling the duration of each half // of the step cycle. // microseconds/half-step = (1000000 microseconds/second) * (1 step/2 half-steps) / (steps/second) unsigned long wait_time = 500000/speed; // The delayMicroseconds() function cannot wait more than 16.383ms, so the // total delay is separated into millisecond and microsecond components. This // increases the range of speeds this function can handle. unsigned int msec = wait_time / 1000; unsigned int usec = wait_time - (1000*msec); // Print a status message to the console. Serial.print( "Beginning rotation of " ); Serial.print(steps); Serial.print( " steps with delay interval of " ); Serial.print(msec); Serial.print( " milliseconds, " ); Serial.print(usec); Serial.print( " microseconds.\n" ); // Loop for the given number of step cycles. The driver will change outputs // on the rising edge of the step signal so short pulses would work fine, but // this produces a square wave for easier visualization on a scope. for ( int i = 0; i < pulses; i++) { digitalWrite(STEP_PIN, HIGH); if (msec > 0) delay(msec); if (usec > 0) delayMicroseconds(usec); digitalWrite(STEP_PIN, LOW); if (msec > 0) delay(msec); if (usec > 0) delayMicroseconds(usec); } } // ================================================================================ // Run one iteration of the main event loop. The Arduino system will call this // function over and over forever. void loop( void ) { // Begin the motion sequence with a few back-and-forth movements at faster and faster speeds. rotate_stepper( 60, 30.0); rotate_stepper( -60, 30.0); delay(1000); } |
Leave a Reply
You must be logged in to post a comment.