Edwin Foo
/
mbed_stepper
A driver for the stepper motor library
main.cpp@0:351de4c18f59, 2015-04-25 (annotated)
- Committer:
- thef
- Date:
- Sat Apr 25 02:11:40 2015 +0000
- Revision:
- 0:351de4c18f59
mbed_stepper program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thef | 0:351de4c18f59 | 1 | // Oranges and Lemons program |
thef | 0:351de4c18f59 | 2 | #include "mbed.h" |
thef | 0:351de4c18f59 | 3 | |
thef | 0:351de4c18f59 | 4 | PwmOut led(LED1); |
thef | 0:351de4c18f59 | 5 | PwmOut stepper(p22); |
thef | 0:351de4c18f59 | 6 | PwmOut stepper1(p21); |
thef | 0:351de4c18f59 | 7 | |
thef | 0:351de4c18f59 | 8 | DigitalOut led2(LED2); |
thef | 0:351de4c18f59 | 9 | DigitalOut direct(p27); |
thef | 0:351de4c18f59 | 10 | |
thef | 0:351de4c18f59 | 11 | |
thef | 0:351de4c18f59 | 12 | DigitalIn center(p14); // stop |
thef | 0:351de4c18f59 | 13 | DigitalIn up(p15); |
thef | 0:351de4c18f59 | 14 | DigitalIn dwn(p12); |
thef | 0:351de4c18f59 | 15 | |
thef | 0:351de4c18f59 | 16 | |
thef | 0:351de4c18f59 | 17 | |
thef | 0:351de4c18f59 | 18 | float frequency[]={300,400,500,600,700,800 ,900,1000,1500,2000,26000,3000};//frequecy array control the speed of the motor |
thef | 0:351de4c18f59 | 19 | |
thef | 0:351de4c18f59 | 20 | //beat array |
thef | 0:351de4c18f59 | 21 | int main() { |
thef | 0:351de4c18f59 | 22 | // stepper.period(1); |
thef | 0:351de4c18f59 | 23 | |
thef | 0:351de4c18f59 | 24 | //stepper1.period_ms(1000); |
thef | 0:351de4c18f59 | 25 | //stepper2.period_ms(1000); |
thef | 0:351de4c18f59 | 26 | stepper.period(1.0f);// set PWM period buzzer=0.5; // set duty cycle |
thef | 0:351de4c18f59 | 27 | led.period(1.0f); |
thef | 0:351de4c18f59 | 28 | led.write(0.5f);//50% duty cycle |
thef | 0:351de4c18f59 | 29 | stepper.write(0.5f); // 50% duty cycle |
thef | 0:351de4c18f59 | 30 | while (1) |
thef | 0:351de4c18f59 | 31 | { |
thef | 0:351de4c18f59 | 32 | if (up) |
thef | 0:351de4c18f59 | 33 | direct = 1 ; |
thef | 0:351de4c18f59 | 34 | else if(dwn) |
thef | 0:351de4c18f59 | 35 | direct =0; |
thef | 0:351de4c18f59 | 36 | else if(center) |
thef | 0:351de4c18f59 | 37 | { |
thef | 0:351de4c18f59 | 38 | led.write(0.5f);//50% duty cycle |
thef | 0:351de4c18f59 | 39 | stepper.write(0.5f); // 50% duty cycle |
thef | 0:351de4c18f59 | 40 | led2 = 1; |
thef | 0:351de4c18f59 | 41 | } |
thef | 0:351de4c18f59 | 42 | |
thef | 0:351de4c18f59 | 43 | for (int i=1; i<=3000; i+=1) |
thef | 0:351de4c18f59 | 44 | { |
thef | 0:351de4c18f59 | 45 | |
thef | 0:351de4c18f59 | 46 | //stepper1 =1; |
thef | 0:351de4c18f59 | 47 | // stepper.period(1.0f/i);// set PWM period buzzer=0.5; // set duty cycle |
thef | 0:351de4c18f59 | 48 | led.period(1.0f/i); |
thef | 0:351de4c18f59 | 49 | led.write(0.5f); |
thef | 0:351de4c18f59 | 50 | wait(5);// hold for beat period |
thef | 0:351de4c18f59 | 51 | //LED=0; |
thef | 0:351de4c18f59 | 52 | /* |
thef | 0:351de4c18f59 | 53 | stepper1 = 0; |
thef | 0:351de4c18f59 | 54 | wait_ms(5); |
thef | 0:351de4c18f59 | 55 | */ |
thef | 0:351de4c18f59 | 56 | } |
thef | 0:351de4c18f59 | 57 | } |
thef | 0:351de4c18f59 | 58 | } |