Armin Klacar Ensar Muratovic

Dependencies:   mbed

Committer:
tim003
Date:
Thu May 15 16:03:48 2014 +0000
Revision:
0:1e96a516f571
LV9-Zadatak2-Grupa6-Tim003

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tim003 0:1e96a516f571 1 #include "mbed.h"
tim003 0:1e96a516f571 2
tim003 0:1e96a516f571 3 Serial pc(USBTX, USBRX);
tim003 0:1e96a516f571 4 Ticker run;
tim003 0:1e96a516f571 5 BusOut motor(dp13, dp11, dp10, dp9); //IN1, IN2, IN3, IN4
tim003 0:1e96a516f571 6 int anticlockwise[8] = {1, 3, 2, 6, 4, 12, 8, 9};
tim003 0:1e96a516f571 7 int clockwise[8] = {9, 8, 12, 4, 6, 2, 3, 1};
tim003 0:1e96a516f571 8 int speed = 1200;
tim003 0:1e96a516f571 9 bool startstop = false;
tim003 0:1e96a516f571 10 bool direction = true;
tim003 0:1e96a516f571 11 int stepen = 360;
tim003 0:1e96a516f571 12 double x = 0.703125;
tim003 0:1e96a516f571 13 void spin(){
tim003 0:1e96a516f571 14 switch (direction) {
tim003 0:1e96a516f571 15 case true: {for (int i = 0; i < 8; i++) {motor = clockwise[i];wait_us(speed);}} break;
tim003 0:1e96a516f571 16 case false: {for (int i = 0; i < 8; i++) {motor = anticlockwise[i];wait_us(speed);}} break;
tim003 0:1e96a516f571 17 }
tim003 0:1e96a516f571 18 }
tim003 0:1e96a516f571 19
tim003 0:1e96a516f571 20 int main()
tim003 0:1e96a516f571 21 {
tim003 0:1e96a516f571 22
tim003 0:1e96a516f571 23 while (1){
tim003 0:1e96a516f571 24
tim003 0:1e96a516f571 25
tim003 0:1e96a516f571 26 if (pc.readable()){
tim003 0:1e96a516f571 27 char c = pc.getc();
tim003 0:1e96a516f571 28
tim003 0:1e96a516f571 29 if(c=='A'){
tim003 0:1e96a516f571 30 pc.scanf ("%d",&stepen);
tim003 0:1e96a516f571 31 for (int i=0; i<(stepen/x);i++) spin();
tim003 0:1e96a516f571 32
tim003 0:1e96a516f571 33 }
tim003 0:1e96a516f571 34 else if (c=='B')direction = !direction;
tim003 0:1e96a516f571 35 else if(c=='C') pc.scanf ("%d",&speed);
tim003 0:1e96a516f571 36 else if (c=='D') startstop=!startstop;
tim003 0:1e96a516f571 37 }
tim003 0:1e96a516f571 38
tim003 0:1e96a516f571 39 if (startstop) spin();
tim003 0:1e96a516f571 40
tim003 0:1e96a516f571 41
tim003 0:1e96a516f571 42
tim003 0:1e96a516f571 43 }
tim003 0:1e96a516f571 44 }