
The code for our ball controller
Diff: main.cpp
- Revision:
- 0:55df798632e3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Apr 08 20:04:36 2012 +0000 @@ -0,0 +1,111 @@ +#include "mbed.h" + +AnalogIn topStickVert(p15); +AnalogIn topStickHorz(p16); +AnalogIn botStickVert(p17); +AnalogIn botStickHorz(p18); + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + + +//xBee +Serial xbee(p13, p14); //tx, rx +DigitalOut rstXbee(p21); + +Serial pc(USBTX, USBRX); // tx, rx + +int main() { + rstXbee = 0; + wait_ms(1); + rstXbee=1; + wait_ms(1); + + myled1 = 1; + wait(0.1); + myled2 = 1; + myled1 = 0; + wait(0.1); + myled2=0; + + + + while(1) { + + pc.printf("READY!... "); + + /* pc.printf("Top VERT: %f ", topStickVert.read()); + pc.printf("Top HORZ: %f ", topStickHorz.read()); + pc.printf("Bot VERT: %f ", botStickVert.read()); + pc.printf("Bot HORZ: %f \r\n", botStickHorz.read());*/ + + + + + if(topStickHorz.read()==1.00){ + myled1=1; + if(xbee.writeable()){ + xbee.putc('l'); + pc.printf("l... "); + } + } + else{ + myled1=0; + } + + if(topStickHorz.read()<0.01){ + myled2=1; + if(xbee.writeable()){ + xbee.putc('r'); + pc.printf("r... "); + } + } + else{ + myled2=0; + } + + if(botStickVert.read()==1.00){ + myled3=1; + if(xbee.writeable()){ + xbee.putc('f'); + pc.printf("f... "); + } + } + else{ + myled3=0; + } + + if(botStickVert.read()<0.01){ + myled4=1; + if(xbee.writeable()){ + xbee.putc('b'); + pc.printf("b... "); + } + } + else{ + myled4=0; + } + + if(botStickVert.read()>0.25&&botStickVert.read()<.75&&topStickHorz.read()>0.25&&topStickHorz.read()<.75){ + if(xbee.writeable()){ + xbee.putc('0'); + pc.printf("0... "); + } + } + + pc.printf("\r\n"); + + } +} + +/* Controller Functionality Notes + +Modules to Processs joystick data + +Joystick 1 Module + - ADC for the values from two potentioeters(10kOhms) on the joystick will dictate what data is passed to the balls mbed + - the two potentiometerscorrspond to a x-axis value and a y axis value. + +JoyStick 2 Module */ \ No newline at end of file