tim003 tim003
/
LV9_Zadatak2_Grupa6_Tim003
Armin Klacar Ensar Muratovic
Diff: main.cpp
- Revision:
- 0:1e96a516f571
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 15 16:03:48 2014 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); +Ticker run; +BusOut motor(dp13, dp11, dp10, dp9); //IN1, IN2, IN3, IN4 +int anticlockwise[8] = {1, 3, 2, 6, 4, 12, 8, 9}; +int clockwise[8] = {9, 8, 12, 4, 6, 2, 3, 1}; +int speed = 1200; +bool startstop = false; +bool direction = true; +int stepen = 360; +double x = 0.703125; +void spin(){ + switch (direction) { + case true: {for (int i = 0; i < 8; i++) {motor = clockwise[i];wait_us(speed);}} break; + case false: {for (int i = 0; i < 8; i++) {motor = anticlockwise[i];wait_us(speed);}} break; + } + } + +int main() +{ + + while (1){ + + +if (pc.readable()){ + char c = pc.getc(); + + if(c=='A'){ + pc.scanf ("%d",&stepen); + for (int i=0; i<(stepen/x);i++) spin(); + + } + else if (c=='B')direction = !direction; + else if(c=='C') pc.scanf ("%d",&speed); + else if (c=='D') startstop=!startstop; +} + + if (startstop) spin(); + + + + } +} \ No newline at end of file