Armin Klacar Ensar Muratovic

Dependencies:   mbed

main.cpp

Committer:
tim003
Date:
2014-05-15
Revision:
0:1e96a516f571

File content as of revision 0:1e96a516f571:

#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();
        
        
        
        }
}