Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 BusOut StepperMotor1(PA_7, PB_6, PC_7, PA_9); 00004 InterruptIn User_Button(PC_13); 00005 00006 00007 //Variables 00008 Timer timer; 00009 static int iValg = 6; 00010 00011 00012 //Prototypes 00013 void DriveStepperCW(int); 00014 void DriveStepperCCW(int); 00015 00016 void Interrupt() 00017 { 00018 printf("Interrupt\n"); 00019 iValg = 6; 00020 } 00021 00022 int main() 00023 { 00024 printf("Welcome\r\n"); 00025 00026 00027 //Start timer 00028 timer.start(); 00029 User_Button.fall(&Interrupt); 00030 00031 //Variables 00032 int first = 1; 00033 00034 00035 00036 00037 00038 while(1) 00039 { 00040 switch (iValg) 00041 { 00042 case 0: 00043 { 00044 if(first) 00045 { 00046 printf("Rotate one round CW\r\n"); 00047 first=0; 00048 } 00049 DriveStepperCW(1); 00050 00051 break; 00052 } 00053 00054 case 1: 00055 { 00056 if(first) 00057 { 00058 printf("Rotate one round CCW\r\n"); 00059 00060 first=0; 00061 00062 } 00063 DriveStepperCCW(1); 00064 00065 00066 break; 00067 } 00068 00069 00070 00071 00072 default: 00073 { 00074 printf("Option:\r\n"); 00075 printf("0 = Rotate one round CW\r\n"); 00076 printf("1 = Rotate one round CCW\r\n"); 00077 printf("\n\r\n"); 00078 00079 scanf("%d", &iValg); 00080 00081 first = 1; 00082 break; 00083 } 00084 } 00085 } 00086 00087 } 00088 00089 void DriveStepperCW(int round) 00090 { 00091 if(round == 0) 00092 { 00093 while(iValg <5) 00094 { 00095 StepperMotor1 = 0x3; 00096 wait_ms(10); 00097 StepperMotor1 = 0x6; 00098 wait_ms(10); 00099 StepperMotor1 = 0xc; 00100 wait_ms(10); 00101 StepperMotor1 = 0x9; 00102 wait_ms(10); 00103 } 00104 } 00105 else 00106 { 00107 00108 int step = 360/(5.625/64)/4/2*round; 00109 00110 while(iValg <5) 00111 { 00112 for(int i = 0; i < step; i++) 00113 { 00114 StepperMotor1 = 0x3; 00115 wait_ms(10); 00116 StepperMotor1 = 0x6; 00117 wait_ms(10); 00118 StepperMotor1 = 0xc; 00119 wait_ms(10); 00120 StepperMotor1 = 0x9; 00121 wait_ms(10); 00122 } 00123 iValg = 6; 00124 } 00125 } 00126 } 00127 00128 void DriveStepperCCW(int round) 00129 { 00130 if(round == 0) 00131 { 00132 00133 00134 while(iValg <5) 00135 { 00136 00137 StepperMotor1 = 0x9; 00138 wait_ms(10); 00139 StepperMotor1 = 0xC; 00140 wait_ms(10); 00141 StepperMotor1 = 0x6; 00142 wait_ms(10); 00143 StepperMotor1 = 0x3; 00144 wait_ms(10); 00145 } 00146 } 00147 else 00148 { 00149 00150 int step = 360/(5.625/64)/4/2*round; 00151 00152 while(iValg <5) 00153 { 00154 for(int i = 0; i < step; i++) 00155 { 00156 StepperMotor1 = 0x9; 00157 wait_ms(10); 00158 StepperMotor1 = 0xC; 00159 wait_ms(10); 00160 StepperMotor1 = 0x6; 00161 wait_ms(10); 00162 StepperMotor1 = 0x3; 00163 wait_ms(10); 00164 } 00165 iValg = 6; 00166 } 00167 } 00168 }
Generated on Mon Jul 25 2022 12:30:56 by
