Provides an API software interface to TIMER2 to control upto four stepper motors.

Dependents:   Steppermotor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers example1.h Source File

example1.h

00001 
00002 #include "mbed.h"
00003 #include "SimpleSteppers.h"
00004 
00005 SimpleStepperOutput led1(LED1);
00006 
00007 // SimpleStepperOutput is basically the same as
00008 // Mbed's DigitalOut class. However, it's more
00009 // portable to other platforms without having
00010 // to also port the entire Mbed library.
00011 SimpleStepperOutput sdir0(p17);
00012 SimpleStepperOutput sdir1(p18);
00013 SimpleStepperOutput sdir2(p19);
00014 SimpleStepperOutput sdir3(p20);
00015 
00016 // Create four steppers.
00017 // Stepper0 has the pulse output on p8 and dir on p17
00018 SimpleStepper stepper0(p8, &sdir0);
00019 // Stepper1 has the pulse output on p7 and dir on p18
00020 SimpleStepper stepper1(p7, &sdir1);
00021 // Stepper2 has the pulse output on p7 and dir on p19
00022 SimpleStepper stepper2(p6, &sdir2);
00023 // Stepper3 has the pulse output on p7 and dir on p20
00024 SimpleStepper stepper3(p5, &sdir3);
00025 
00026 int main() {
00027 
00028     // We do not need to maintain the stepper position
00029     // for this simple example. This reduces the amount
00030     // of work the ISR has to do.
00031     stepper0.setMaintainPositionData(false);
00032     stepper1.setMaintainPositionData(false);
00033     stepper2.setMaintainPositionData(false);
00034     stepper3.setMaintainPositionData(false);
00035     
00036     // Set all steppers to top speed of 5000 pulses/second.
00037     stepper0.setSpeed(5000);
00038     stepper1.setSpeed(5000);
00039     stepper2.setSpeed(5000);
00040     stepper3.setSpeed(5000);
00041 
00042     while(1) {
00043         led1 = !led1;
00044         wait(0.2);        
00045     }
00046 }