Test with BBB (Freeduino) board, Darlington H-Bridge, Mabuchi # PF35T-48L4 stepper motor. Many thanks to Tom Igoe and his Physical computing book.
-
/*
-
Owen Mundy
-
July 29, 2009
-
-
p. 262 of Physical Computing
-
Using BBB to run stepper motor by manually moving steppers
-
-
*/
-
-
int pin1 = 3; // PWM
-
int pin2 = 5; // PWM
-
int pin3 = 6; // PWM
-
int pin4 = 9; // PWM
-
int ledpin = 13; // LED
-
-
void setup()
-
{
-
pinMode(pin1, OUTPUT); // sets the pin as output
-
pinMode(pin2, OUTPUT); // sets the pin as output
-
pinMode(pin3, OUTPUT); // sets the pin as output
-
pinMode(pin4, OUTPUT); // sets the pin as output
-
pinMode(ledpin, OUTPUT); // sets the pin as output
-
}
-
-
void loop()
-
{
-
for (int i=0; i<24; i++)
-
{
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
}
-
-
blink();
-
-
for (int i=0; i<24; i++)
-
{
-
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
}
-
-
blink();
-
-
for (int i=0; i<6; i++)
-
{
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
}
-
-
blink();
-
-
for (int i=0; i<6; i++)
-
{
-
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, LOW); // off
-
digitalWrite(pin4, HIGH); // on
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, LOW); // off
-
digitalWrite(pin2, HIGH); // on
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
-
digitalWrite(pin1, HIGH); // on
-
digitalWrite(pin2, LOW); // off
-
digitalWrite(pin3, HIGH); // on
-
digitalWrite(pin4, LOW); // off
-
delay(10); // waits for a second
-
}
-
-
blink();
-
-
}
-
-
void blink()
-
{
-
digitalWrite(ledpin, HIGH); // on
-
delay(1000); // waits for a second
-
digitalWrite(ledpin, LOW); // off
-
}
You must be logged in to post a comment.