EE149
/
FinalProject
Final Project files for mBed development.
main.c
- Committer:
- lsaristo
- Date:
- 2014-11-15
- Revision:
- 10:94b068b2ce1d
- Parent:
- 9:3a0433c391cb
- Child:
- 11:a30f30d3066e
File content as of revision 10:94b068b2ce1d:
/** * @file driver.c * @brief Basic driver program for our robot's controller logic. * * Maybe add lots of stuff here or maybe split it off into * multiple subfiles? * * @author John Wilkey */ #include "main.h" #include "control.h" /** * These are global data Used externally in all other files */ m3pi pi; // // Digital inputs to the mBed DigitalIn start_button(p21); // // Digital outputs from the mBed. Note that by default these are // used to drive the 8 LED's on the top board. DigitalOut pin15(p15); DigitalOut pin16(p16); DigitalOut pin17(p17); DigitalOut pin18(p18); DigitalOut pin19(p19); DigitalOut pin20(p20); // // mBed onboard LEDs DigitalOut oled_1(LED1); DigitalOut oled_2(LED2); DigitalOut oled_3(LED3); DigitalOut oled_4(LED4); /** * @brief Entry point. Main loop. */ int main() { // // Basic setup information start_button.mode(PullUp); pi.locate(0,0); pi.printf("PiCO"); pi.locate(0,1); pi.printf("%f mV", pi.battery()); wait(.2); while(!start_button) { oled_2 = 1; wait(.2); pi.locate(0,0); pi.printf("Ready"); oled_2 = 0; } pi.locate(0,0); pi.printf("GO!"); wait(.2); // // Main program loop. robot_loop(); // // We should never reach this point! } int forward(int amt) { oled_2 = 1; pi.locate(0,0); pi.printf("Fwd %d", amt); pi.forward(DRIVE_SPEED); wait(amt*DRIVE_RATE); oled_2 = 0; return EXIT_SUCCESS; } int backward(int amt) { oled_3 = 1; pi.locate(0,0); pi.printf("Back %d", amt); pi.backward(DRIVE_SPEED); wait(amt*DRIVE_RATE); oled_3 = 0; return EXIT_SUCCESS; } int right(float deg) { oled_4 = 1; pi.locate(0,0); pi.printf("Right %f", deg); pi.right(TURN_SPEED); wait(deg/360); oled_4 = 0; return EXIT_SUCCESS; } int left(float deg) { oled_4 = 1; oled_2 = 1; pi.locate(0,0); pi.printf("Left %f", deg); pi.left(TURN_SPEED); wait(deg/360); oled_4 = 0; oled_2 = 0; return EXIT_SUCCESS; } void pen_down() { oled_1 = 1; } void pen_up() { oled_1 = 0; }