3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Drive a Stepper Motor with an AVR Microprocessor

Step 5Swing it Back and Forth

So you've got it running clockwise. Anything more interesting?

A little code-cleanup, and we can run it back and forth.

I put the clockwise sequence into an array so that you can step through the phases with a simple for loop. Now you can run the loop up or down to go clockwise or counterclockwise.

int main(void){  const uint8_t delay = 50;  const uint8_t clockwise[] = {BLUE, BLACK, RED, YELLOW};  uint8_t i;  DDRB = 0xff;                  /* Enable output on all of the B pins */  PORTB = 0x00;                 /* Set them all to 0v */  while(1){                     /* main loop here */    for ( i=0; i<=3; i++ ){     /* step through the colors clockwise */      PORTB = clockwise[i];      _delay_ms(delay);    }    for ( i=3; i>=0; i-- ){     /* step through the colors ccw */      PORTB = clockwise[i];      _delay_ms(delay);    }  }}

See the racy video for the back-and-forthing.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
95
Followers
7
Author:The Real Elliot