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.
main.cpp
00001 /* 00002 ############################################ 00003 ## sMotor v0.1 Test Program ## 00004 ## created by Samuel Matildes ## 00005 ############################################ 00006 ---- sam.naeec@gmail.com ----- 00007 This library was made for 4-Phase Stepper Motors 00008 I don't take any resposability for the damage caused to your equipment. 00009 00010 */ 00011 00012 #include "mbed.h" 00013 #include "sMotor.h" 00014 00015 00016 Serial pc(USBTX, USBRX); 00017 sMotor motor(p9, p10, p11, p12); // creates new stepper motor: IN1, IN2, IN3, IN4 00018 00019 int step_speed = 1200 ; // set default motor speed 00020 int numstep = 512 ; // defines full turn of 360 degree 00021 //you might want to calibrate this value according to your motor 00022 00023 00024 int main() { 00025 00026 //Credits 00027 printf("4 Phase Stepper Motor v0.1 - Test Program\r\n"); 00028 printf("developed by Samuel Matildes\r\n"); 00029 printf("\n\r"); 00030 00031 // Screen Menu 00032 printf("Default Speed: %d\n\r",step_speed); 00033 printf("1- 360 degree clockwise step\n\r"); 00034 printf("2- 360 degree anticlockwise step\n\r"); 00035 printf("3- 180 degree clockwise step\n\r"); 00036 printf("4- 180 degree anticlockwise step\n\r"); 00037 printf("5- Change Speed\n\r"); 00038 00039 while (1) { 00040 00041 if (pc.readable()) { // checks for serial 00042 00043 if (pc.getc()=='1') 00044 motor.step(numstep,0,step_speed); // number of steps, direction, speed 00045 00046 if (pc.getc()=='2') 00047 motor.step(numstep,1,step_speed); 00048 00049 if (pc.getc()=='3') 00050 motor.step(numstep/2,0,step_speed); 00051 00052 if (pc.getc()=='4') 00053 motor.step(numstep/2,1,step_speed); 00054 00055 if (pc.getc()=='5') { 00056 printf("Current Speed: %d\n\r", step_speed); 00057 printf("New speed: \n\r"); 00058 pc.scanf("%d",&step_speed); // sets new speed 00059 } 00060 } 00061 } 00062 }
Generated on Tue Jul 12 2022 11:34:35 by
