tim003 tim003
/
PAI_Grupa7_LV9_Tim003_Zadatak2
Nedim Hozić Selma Tucak
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "sMotor.h" 00003 00004 Serial pc(USBTX, USBRX); 00005 sMotor motor(dp13, dp11, dp10, dp9); 00006 00007 int step_speed = 0; 00008 int numstep = 512; 00009 int direction = 0; 00010 int main() { 00011 pc.printf("O - Postavljanje osovine u proizvoljan polozaj. \n"); 00012 pc.printf("P - Promjena smjera okretanja. \n"); 00013 pc.printf("B - Promjena brzine okretanja. \n"); 00014 pc.printf("K - Pokreni motor. \n"); 00015 pc.printf("S - Zustavi motor. \n"); 00016 pc.printf("Trenutna brzina je %d", step_speed); 00017 step_speed=1200; 00018 while(1) { 00019 if(pc.readable()) 00020 { 00021 char a = pc.getc(); 00022 if(a=='O') 00023 { 00024 int ugao; 00025 pc.printf("\nUnesi ugao: "); 00026 pc.scanf("%d", &ugao); 00027 numstep = (ugao/360.00)*512; 00028 motor.step(numstep,direction,step_speed); 00029 } 00030 if(a=='P') 00031 { 00032 numstep = 512; 00033 if(direction==0) 00034 { 00035 motor.anticlockwise(); 00036 direction = 1; 00037 } 00038 else 00039 { 00040 motor.clockwise(); 00041 direction = 0; 00042 } 00043 motor.step(numstep,direction,step_speed); 00044 } 00045 if(a=='B') 00046 { 00047 pc.printf("Trenutna brzina je %d, unesite novu: "); 00048 pc.scanf("%d", &step_speed); 00049 motor.step(numstep,direction,step_speed); 00050 } 00051 if(a=='K') 00052 { 00053 if(step_speed==0) 00054 step_speed = 1200; 00055 motor.step(numstep,direction,step_speed); 00056 } 00057 if(a=='S') 00058 { 00059 motor.step(0,direction,step_speed); 00060 } 00061 } 00062 } 00063 }
Generated on Wed Jul 20 2022 00:06:56 by 1.7.2