tim003 tim003
/
LV9_Zadatak2_Grupa6_Tim003
Armin Klacar Ensar Muratovic
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX, USBRX); 00004 Ticker run; 00005 BusOut motor(dp13, dp11, dp10, dp9); //IN1, IN2, IN3, IN4 00006 int anticlockwise[8] = {1, 3, 2, 6, 4, 12, 8, 9}; 00007 int clockwise[8] = {9, 8, 12, 4, 6, 2, 3, 1}; 00008 int speed = 1200; 00009 bool startstop = false; 00010 bool direction = true; 00011 int stepen = 360; 00012 double x = 0.703125; 00013 void spin(){ 00014 switch (direction) { 00015 case true: {for (int i = 0; i < 8; i++) {motor = clockwise[i];wait_us(speed);}} break; 00016 case false: {for (int i = 0; i < 8; i++) {motor = anticlockwise[i];wait_us(speed);}} break; 00017 } 00018 } 00019 00020 int main() 00021 { 00022 00023 while (1){ 00024 00025 00026 if (pc.readable()){ 00027 char c = pc.getc(); 00028 00029 if(c=='A'){ 00030 pc.scanf ("%d",&stepen); 00031 for (int i=0; i<(stepen/x);i++) spin(); 00032 00033 } 00034 else if (c=='B')direction = !direction; 00035 else if(c=='C') pc.scanf ("%d",&speed); 00036 else if (c=='D') startstop=!startstop; 00037 } 00038 00039 if (startstop) spin(); 00040 00041 00042 00043 } 00044 }
Generated on Sun Aug 7 2022 14:46:34 by 1.7.2