Engine control program with 3 engines Needs to make a case for each simultaneous engine setting, because of the WAIT after each number of bits have been sent.

Dependencies:   mbed-rtos mbed PinDetect

Fork of FinalMotorControl by Robot Bachelor

main.cpp

Committer:
mjhaugsdal
Date:
2016-04-08
Revision:
3:15be78948724
Parent:
2:25bcc26f7a5b
Child:
4:4d655fdae399

File content as of revision 3:15be78948724:

#include "mbed.h"
#include "rtos.h"

Serial pc(USBTX, USBRX); // tx, rx

//Analog Pins
DigitalOut IN1(D3);
DigitalOut IN2(D4);
DigitalOut IN3(D5);
DigitalOut IN4(D6);

static int fart = 1000;
static char m_cmd = 'x';


void step4Right()
{
    IN1=0;
    IN2=1;
    IN3=0;
    IN4=1;
    wait_us(fart); //legg som global variabel "fart" 
    IN1=0;
    IN2=1;
    IN3=1;
    IN4=0;
    wait_us(fart);
    IN1=1;
    IN2=0;
    IN3=1;
    IN4=0;
    wait_us(fart);
    IN1=1;
    IN2=0;
    IN3=0;
    IN4=1;
    wait_us(fart);
}
void step4Left()
{
    IN1=1;
    IN2=0;
    IN3=0;
    IN4=1;
    wait_us(fart);

    IN1=1;
    IN2=0;
    IN3=1;
    IN4=0;
    wait_us(fart);

    IN1=0;
    IN2=1;
    IN3=1;
    IN4=0;
    wait_us(fart);

    IN1=0;
    IN2=1;
    IN3=0;
    IN4=1;
    wait_us(fart);
}

  
void input(void const *args)
{
    while(true)
    {

        if(pc.readable()) 
        { m_cmd=pc.getc(); 
        
         }
        
        Thread::wait(10);
    }
}

int main()
{
        //Thread 1 has constant feed from usb
        Thread t1(input);
        static char global_direction;
        printf("Started");
        
        while (true) 
        {
            
    
            if (m_cmd == '0')
            {
                global_direction = '0';
                step4Left();
                //printf("%c \n" + global_direction); 
            } 
            else if (m_cmd == '1')
            {
                global_direction = '1';
                step4Right();
                //printf("RIGHT \n"); 
            } 
            if (m_cmd == 'a')
            {
                fart = 1000;
                
            }
            else if (m_cmd == 'b')
            {
                fart = 5000;
            }
            if (global_direction =='0')
            {
                step4Left();
            }
            else if (global_direction == '1')
            {
                step4Right();
            }
            else
            {
                global_direction = 'x';
            }
        }  
            
} //END Main