picolo
Fork of Step_Motor by
Diff: Step_Motor.cpp
- Revision:
- 4:8581e6927b36
- Parent:
- 3:ec3add9f1351
- Child:
- 5:d92004b211c9
--- a/Step_Motor.cpp Tue Apr 24 15:48:13 2018 +0000 +++ b/Step_Motor.cpp Wed Apr 25 13:33:03 2018 +0000 @@ -1,5 +1,6 @@ #include "Step_Motor.h" #include "mbed.h" +#include "General.h" Serial pc1(USBTX,USBRX); @@ -10,7 +11,7 @@ motor_out=0x0; nstep=0; - motorSpeed=1100; + motorSpeed=1200; nstep2=7; } @@ -19,28 +20,28 @@ switch(nstep2) { - case 0: ms2 = 0x1; break; // 0001 + case 0: ms2 = 0x1; break; // 0001 XXXX case 1: ms2 = 0x3; break; // 0011 - case 2: ms2 = 0x2; break; // 0010 - case 3: ms2 = 0x6; break; // 0110 - case 4: ms2 = 0x4; break; // 0100 - case 5: ms2 = 0xC; break; // 1100 - case 6: ms2 = 0x8; break; // 1000 - case 7: ms2 = 0x9; break; // 1001 + case 2: ms2 = 0x2; break; // 0010 + case 3: ms2 = 0x6; break; // 0110 + case 4: ms2 = 0x4; break; // 0100 + case 5: ms2 = 0xC; break; // 1100 + case 6: ms2 = 0x8; break; // 1000 + case 7: ms2 = 0x9; break; // 1001 default: ms2 = 0x0; break; // 0000 } switch(nstep) { - case 0: motor_out = 0x10 + ms2; break; // 0001 XXXX + case 0: motor_out = 0x10 + ms2; break; // 0001 XXXX case 1: motor_out = 0x30 + ms2; break; // 0011 - case 2: motor_out = 0x20 + ms2; break; // 0010 - case 3: motor_out = 0x60 + ms2; break; // 0110 - case 4: motor_out = 0x40 + ms2; break; // 0100 - case 5: motor_out = 0xC0 + ms2; break; // 1100 - case 6: motor_out = 0x80 + ms2; break; // 1000 - case 7: motor_out = 0x90 + ms2; break; // 1001 + case 2: motor_out = 0x20 + ms2; break; // 0010 + case 3: motor_out = 0x60 + ms2; break; // 0110 + case 4: motor_out = 0x40 + ms2; break; // 0100 + case 5: motor_out = 0xC0 + ms2; break; // 1100 + case 6: motor_out = 0x80 + ms2; break; // 1000 + case 7: motor_out = 0x90 + ms2; break; // 1001 default: motor_out = 0x00 + ms2; break; // 0000 } @@ -65,15 +66,20 @@ uint32_t count=num_steps ; while(count){ - if (cw==1) nstep++; - if (cw==0) nstep--; + if (cw==DER) nstep++; nstep2++; + if (cw==IZQ) nstep--; nstep2--; + if (cw==UP) nstep++; nstep2--; + if (cw==DOWN) nstep--; nstep2++; if (nstep>7) nstep=0; if (nstep<0) nstep=7; - nstep2=7-nstep; + if (nstep2>7) nstep=0; + if (nstep2<0) nstep=7; move(); count--; } - if(cw==1) pc1.printf("Avance \n"); - else if (cw==0) pc1.printf("Retrocedi \n"); + if(cw==UP) pc1.printf("Avance \n"); + else if (cw==DOWN) pc1.printf("Retrocedi \n"); + else if (cw==IZQ) pc1.printf("Gire Izq \n"); + else if (cw==DER) pc1.printf("Gire Der \n"); } \ No newline at end of file