EE149
/
FinalProject
Final Project files for mBed development.
Diff: main.c
- Revision:
- 9:3a0433c391cb
- Parent:
- 8:12d780f7443e
- Child:
- 10:94b068b2ce1d
--- a/main.c Thu Nov 13 07:12:31 2014 +0000 +++ b/main.c Sat Nov 15 05:07:24 2014 +0000 @@ -7,12 +7,20 @@ * * @author John Wilkey */ -#include "project.h" +#include "main.h" /** * These are global data Used externally in all other files */ m3pi pi; + +// +// Digital inputs to the mBed +DigitalIn btn_b(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); @@ -20,43 +28,65 @@ 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() { - pretty_print("PiCO"); - - while(1) { - wait(2); - forward(10, DRIVE_SPEED); - wait(2); - backward(10, DRIVE_SPEED); - } + // + // Basic setup information + DigitalOut olen_1(LED1); + pi.locate(0,0); + pi.printf("PiCO"); + pi.locate(0,1); + pi.printf("%f mV", pi.battery()); // - // Our code should NEVER reach this point. - return EXIT_FAILURE; + // Main program loop. + while(1) { + forward(10); + right(90); + forward(10); + right(90); + forward(10); + wait(2); + left(180); + } + + // + // We should never reach this point! } -int forward(float amt, float spd) +int forward(int amt) { - if(amt > 1) { spd = 1; } - pi.forward(spd); - wait(amt); + pi.locate(0,0); + pi.printf("Fwd %d", amt); + pi.forward(DRIVE_SPEED); + wait(amt*DRIVE_RATE); return EXIT_SUCCESS; } -int backward(float amt, float spd) +int backward(int amt) { - if(amt > 1) { spd = 1; } - pi.backward(spd); - wait(amt); + pi.locate(0,0); + pi.printf("Back %d", amt); + pi.backward(DRIVE_SPEED); + wait(amt*DRIVE_RATE); return EXIT_SUCCESS; } int right(float deg) { + pi.locate(0,0); + pi.printf("Right %f", deg); pi.right(TURN_SPEED); wait(deg/360); return EXIT_SUCCESS; @@ -64,14 +94,9 @@ int left(float deg) { + pi.locate(0,0); + pi.printf("Left %f", deg); pi.left(TURN_SPEED); wait(deg/360); return EXIT_SUCCESS; -} - -void pretty_print(char* msg) -{ - pi.locate(0,1); - pi.printf(msg); -} - +} \ No newline at end of file