Coby Lu / direction

Dependents:   snake

Committer:
lucoby
Date:
Thu Oct 11 18:54:32 2012 +0000
Revision:
0:d8f0c4ba09cc
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lucoby 0:d8f0c4ba09cc 1 #include "mbed.h"
lucoby 0:d8f0c4ba09cc 2 #include "direction.h"
lucoby 0:d8f0c4ba09cc 3
lucoby 0:d8f0c4ba09cc 4 AnalogIn horz(p18);
lucoby 0:d8f0c4ba09cc 5 AnalogIn vert(p19);
lucoby 0:d8f0c4ba09cc 6
lucoby 0:d8f0c4ba09cc 7 SDirection getDirection(SDirection direction) {
lucoby 0:d8f0c4ba09cc 8 float x = horz;
lucoby 0:d8f0c4ba09cc 9 float y = vert;
lucoby 0:d8f0c4ba09cc 10 if(vert > 0.75) {
lucoby 0:d8f0c4ba09cc 11 direction = up;
lucoby 0:d8f0c4ba09cc 12 } else if(vert < 0.25) {
lucoby 0:d8f0c4ba09cc 13 direction = down;
lucoby 0:d8f0c4ba09cc 14 } else if(horz > 0.75) {
lucoby 0:d8f0c4ba09cc 15 direction = left;
lucoby 0:d8f0c4ba09cc 16 } else if(horz < 0.25) {
lucoby 0:d8f0c4ba09cc 17 direction = right;
lucoby 0:d8f0c4ba09cc 18 }
lucoby 0:d8f0c4ba09cc 19 return direction;
lucoby 0:d8f0c4ba09cc 20 }