wheelchair code for driver assitance

Dependencies:   mbed

Fork of wheelchairalexa by ryan lin

main.cpp

Committer:
ryanlin97
Date:
2018-08-17
Revision:
12:0e5a0571b497
Parent:
11:75f0f13ff6c1

File content as of revision 12:0e5a0571b497:

#include "wheelchair.h"

AnalogIn x(A0);
AnalogIn y(A1);

DigitalOut on(D12);
DigitalOut off(D11);
DigitalOut up(D2);
DigitalOut down(D3);

bool manual = false;
bool leftBound = false;
bool rightBound = false;
bool straightBound = false;

Serial pc(USBTX, USBRX, 9600);
Timer t;

Wheelchair smart(xDir,yDir, &pc, &t);


int main(void)
{
    smart.stop();
    while(1) {
                pc.printf("turning on joystick\n");
                manual = true;
                t.reset();
                while(manual) {
                    smart.move(x,y,leftBound,rightBound,straightBound);
                    if( pc.readable()) {
                        char d = pc.getc();
                        if( d == 'l') {
                            leftBound = true;
                        }

                        if (d == 'e') {
                            leftBound = false;
                        }

                        if( d == 'f') {
                            straightBound = true;
                        }

                        if (d == 'o') {
                            straightBound = false;
                        }

                        if( d == 'r') {
                            rightBound = true;
                        }

                        if( d == 'i') {
                            rightBound = false;
                        }

                        if( d == 'm') {
                            pc.printf("turning off joystick\n");
                            manual = false;
                        }
                    }
                }
            }

    wait(process);
}