Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBHost USBHostXpad mbed-rtos mbed
main.cpp
- Committer:
- jmccranie3
- Date:
- 2014-11-13
- Revision:
- 1:3bae10d2507c
- Parent:
- 0:79485480cd7e
- Child:
- 2:5e870c215495
File content as of revision 1:3bae10d2507c:
#include "mbed.h"
#include "rtos.h"
#include "Traxster.h"
#include "USBHostXpad.h"
#include "utils.h"
#include "Audio.h"
Serial pc(USBTX, USBRX);
Serial robotCom(p13, p14);
AnalogIn ir(p20);
Speaker speaker(p18); // the pin must be the AnalogOut pin - p18
Audio audio(speaker);
USBHostXpad controller;
Xbox360ControllerState controlState;
Traxster tank(robotCom);
//comment added
void onControlInput(int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r){
pc.printf("buttons: %04x Lstick X,Y: %-5d, %-5d Rstick X,Y: %-5d, %-5d LTrig: %02x (%d) RTrig: %02x (%d)\n", buttons, stick_lx, stick_ly, stick_rx, stick_ry, trigger_l,trigger_l, trigger_r,trigger_r);
controlState = Xbox360ControllerState(buttons, stick_lx, stick_ly, stick_rx, stick_ry, trigger_l, trigger_r);
};
void thread_audio_run(void const* arg){
audio.run();
}
int main() {
pc.baud(19200);
controller.attachEvent(&onControlInput);
Thread audio_thread(thread_audio_run);
audio.playMario();
while(1){
//acts as a failsafe
while(controller.connected()) {
if(ir > 0.5){
controller.rumble(255,255);
}
if( controller.read(USBHostXpad::XPAD_PAD_Y) ) {
controller.led( USBHostXpad::LED_ROTATE );
} else {
controller.led( USBHostXpad::LED_OFF );
}
if(controlState.triggerRight > 0){
controller.rumble(255,255);
}
if( controller.read(USBHostXpad::XPAD_PAD_X) ) {
tank.SetMotors(1.0,1.0);
} else {
tank.SetMotors(0.0,0.0); //stop, wait for controller to reconnect for a second.
}
}
tank.SetMotors(0.0,0.0); //stop, wait for controller to reconnect for a second.
Thread::wait(500);
controller.connect();
}
}
