BBB (Freeduino) and stepper motor test

Test with BBB (Freeduino) board, Darlington H-Bridge, Mabuchi # PF35T-48L4 stepper motor. Many thanks to Tom Igoe and his Physical computing book.

  1. /*
  2.   Owen Mundy
  3.   July 29, 2009
  4.  
  5.   p. 262 of Physical Computing
  6.   Using BBB to run stepper motor by manually moving steppers
  7.  
  8. */
  9.  
  10. int pin1 = 3;                 // PWM
  11. int pin2 = 5;                 // PWM
  12. int pin3 = 6;                 // PWM
  13. int pin4 = 9;                 // PWM
  14. int ledpin = 13;              // LED
  15.  
  16. void setup()
  17. {
  18.   pinMode(pin1, OUTPUT);      // sets the pin as output
  19.   pinMode(pin2, OUTPUT);      // sets the pin as output
  20.   pinMode(pin3, OUTPUT);      // sets the pin as output
  21.   pinMode(pin4, OUTPUT);      // sets the pin as output
  22.   pinMode(ledpin, OUTPUT);      // sets the pin as output
  23. }
  24.  
  25. void loop()
  26. {
  27.   for (int i=0; i<24; i++)
  28.   {
  29.     digitalWrite(pin1, HIGH);   // on
  30.     digitalWrite(pin2, LOW);    // off
  31.     digitalWrite(pin3, HIGH);   // on
  32.     digitalWrite(pin4, LOW);    // off
  33.     delay(10);                  // waits for a second
  34.  
  35.     digitalWrite(pin1, LOW);    // off
  36.     digitalWrite(pin2, HIGH);   // on
  37.     digitalWrite(pin3, HIGH);   // on
  38.     digitalWrite(pin4, LOW);    // off
  39.     delay(10);                  // waits for a second
  40.  
  41.     digitalWrite(pin1, LOW);    // off
  42.     digitalWrite(pin2, HIGH);   // on
  43.     digitalWrite(pin3, LOW);    // off
  44.     digitalWrite(pin4, HIGH);   // on
  45.     delay(10);                  // waits for a second
  46.  
  47.     digitalWrite(pin1, HIGH);   // on
  48.     digitalWrite(pin2, LOW);    // off
  49.     digitalWrite(pin3, LOW);    // off
  50.     digitalWrite(pin4, HIGH);   // on
  51.     delay(10);                  // waits for a second
  52.   }
  53.  
  54.   blink();
  55.  
  56.   for (int i=0; i<24; i++)
  57.   {
  58.  
  59.     digitalWrite(pin1, HIGH);   // on
  60.     digitalWrite(pin2, LOW);    // off
  61.     digitalWrite(pin3, LOW);    // off
  62.     digitalWrite(pin4, HIGH);   // on
  63.     delay(10);                  // waits for a second
  64.  
  65.     digitalWrite(pin1, LOW);    // off
  66.     digitalWrite(pin2, HIGH);   // on
  67.     digitalWrite(pin3, LOW);    // off
  68.     digitalWrite(pin4, HIGH);   // on
  69.     delay(10);                  // waits for a second
  70.  
  71.     digitalWrite(pin1, LOW);    // off
  72.     digitalWrite(pin2, HIGH);   // on
  73.     digitalWrite(pin3, HIGH);   // on
  74.     digitalWrite(pin4, LOW);    // off
  75.     delay(10);                  // waits for a second
  76.    
  77.     digitalWrite(pin1, HIGH);   // on
  78.     digitalWrite(pin2, LOW);    // off
  79.     digitalWrite(pin3, HIGH);   // on
  80.     digitalWrite(pin4, LOW);    // off
  81.     delay(10);                  // waits for a second
  82.   }
  83.  
  84.   blink();
  85.  
  86.   for (int i=0; i<6; i++)
  87.   {
  88.     digitalWrite(pin1, HIGH);   // on
  89.     digitalWrite(pin2, LOW);    // off
  90.     digitalWrite(pin3, HIGH);   // on
  91.     digitalWrite(pin4, LOW);    // off
  92.     delay(10);                  // waits for a second
  93.  
  94.     digitalWrite(pin1, LOW);    // off
  95.     digitalWrite(pin2, HIGH);   // on
  96.     digitalWrite(pin3, HIGH);   // on
  97.     digitalWrite(pin4, LOW);    // off
  98.     delay(10);                  // waits for a second
  99.  
  100.     digitalWrite(pin1, LOW);    // off
  101.     digitalWrite(pin2, HIGH);   // on
  102.     digitalWrite(pin3, LOW);    // off
  103.     digitalWrite(pin4, HIGH);   // on
  104.     delay(10);                  // waits for a second
  105.  
  106.     digitalWrite(pin1, HIGH);   // on
  107.     digitalWrite(pin2, LOW);    // off
  108.     digitalWrite(pin3, LOW);    // off
  109.     digitalWrite(pin4, HIGH);   // on
  110.     delay(10);                  // waits for a second
  111.   }
  112.  
  113.   blink();
  114.  
  115.   for (int i=0; i<6; i++)
  116.   {
  117.  
  118.     digitalWrite(pin1, HIGH);   // on
  119.     digitalWrite(pin2, LOW);    // off
  120.     digitalWrite(pin3, LOW);    // off
  121.     digitalWrite(pin4, HIGH);   // on
  122.     delay(10);                  // waits for a second
  123.  
  124.     digitalWrite(pin1, LOW);    // off
  125.     digitalWrite(pin2, HIGH);   // on
  126.     digitalWrite(pin3, LOW);    // off
  127.     digitalWrite(pin4, HIGH);   // on
  128.     delay(10);                  // waits for a second
  129.  
  130.     digitalWrite(pin1, LOW);    // off
  131.     digitalWrite(pin2, HIGH);   // on
  132.     digitalWrite(pin3, HIGH);   // on
  133.     digitalWrite(pin4, LOW);    // off
  134.     delay(10);                  // waits for a second
  135.    
  136.     digitalWrite(pin1, HIGH);   // on
  137.     digitalWrite(pin2, LOW);    // off
  138.     digitalWrite(pin3, HIGH);   // on
  139.     digitalWrite(pin4, LOW);    // off
  140.     delay(10);                  // waits for a second
  141.   }
  142.  
  143.   blink();
  144.  
  145. }
  146.  
  147. void blink()
  148. {
  149.   digitalWrite(ledpin, HIGH); // on  
  150.   delay(1000);                // waits for a second
  151.   digitalWrite(ledpin, LOW);  // off  
  152. }