get direction input from joystick as enum (left, right, up, down, and none)

Dependents:   snake

direction.cpp

Committer:
lucoby
Date:
2012-10-11
Revision:
0:d8f0c4ba09cc

File content as of revision 0:d8f0c4ba09cc:

#include "mbed.h"
#include "direction.h"

AnalogIn horz(p18);
AnalogIn vert(p19);

SDirection getDirection(SDirection direction) {
    float x = horz;
    float y = vert;
    if(vert > 0.75) {
        direction = up;
    } else if(vert < 0.25) {
        direction = down;
    } else if(horz > 0.75) {
        direction = left;
    } else if(horz < 0.25) {
        direction = right;
    }
    return direction;
}