Pajić Enil, Jakić Irma
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "Enil4StepMotor.h" 00003 //By EnilP@ETF-PAI, 11.05.2014 00004 Enil4StepMotor EM (dp13, dp11, dp10, dp9, 100); //(dp9, dp10, dp11, dp13, 100); 00005 Serial PC (USBTX, USBRX); 00006 Ticker T; 00007 bool IsNum (const char C) {return C >= 48 && C <= 57; } 00008 char ToUpper (const char C) {if (C >= 97 && C <= 122) return C - 32; return C;} 00009 bool IsOurChar (const char C) {char E = ToUpper (C); return E == 'O' || E == 'S' || E == 'B' || E == 'P' || E == 'Z'; } 00010 int ToInt (const char *C) {int N = 0; while (*C) if (IsNum (*C)) N = N * 10 + *C++ - 48; else return -7; return N; } 00011 void DoIt () 00012 { 00013 if (!PC.readable()) return; 00014 char C = PC.getc(); 00015 while (!IsOurChar (C)) C = PC.getc(); 00016 C = ToUpper (C); 00017 static char Buff[4] = "000"; 00018 if (C == 'O' || C == 'B') 00019 { 00020 for (int a = 0; a < 3; ++a) Buff[a] = PC.getc(); 00021 int N = -7; 00022 if ((N = ToInt (Buff)) == -7) return; 00023 if (C == 'O') {EM.RotateAbsolute (N);} 00024 else {EM.Speed (N);} 00025 } 00026 else if (C == 'S') 00027 { 00028 char E = PC.getc(); E = ToUpper (E); 00029 if (E == 'D' || E == 'L') EM.ClockWiseDirection() = E == 'D'; 00030 } 00031 else if (C == 'P') EM.Start(), PC.printf ("POKRECEM!\n"); 00032 else if (C == 'Z') EM.Stop(), PC.printf ("ZAUSTAVLJAM!\n"); 00033 } 00034 int main() 00035 { 00036 T.attach (&DoIt, 0.01); //Regulirati: 0.001, 0.05, 0.1 00037 //PC.attach (&DoIt); 00038 while (7); 00039 }
Generated on Thu Jul 21 2022 20:42:45 by
1.7.2