![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Program is a work in progress
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of 4180_Lab4_v6 by
Revision 1:e84085bbf399, committed 2016-10-30
- Comitter:
- ecardenas8
- Date:
- Sun Oct 30 04:39:01 2016 +0000
- Parent:
- 0:9f1095365b9a
- Commit message:
- Program is a work in progress
Changed in this revision
Robot.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Robot.h Sat Oct 29 22:15:03 2016 +0000 +++ b/Robot.h Sun Oct 30 04:39:01 2016 +0000 @@ -2,9 +2,13 @@ class Robot { Mutex stdio_mutex; + int frog_x, frog_y; + public: void drawFrog() { - uLCD.filled_rectangle(XPosition-5,YPosition-5,XPosition+5,YPosition+5,RED); + frog_x=60; + frog_y=115; + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,RED); } void drawOutline() { @@ -90,16 +94,36 @@ } void moveForward() { - setYPosition(getYPosition() - 21); + stdio_mutex.lock(); + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,BLACK); + frog_y=frog_y-6; + + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,RED); + stdio_mutex.unlock(); } void moveBackward() { - setYPosition(getYPosition() + 21); + stdio_mutex.lock(); + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,BLACK); + frog_y=frog_y+6; + + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,RED); + stdio_mutex.unlock(); } void moveLeft() { - setXPosition(getXPosition() - 21); + stdio_mutex.lock(); + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,BLACK); + frog_x=frog_x-6; + + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,RED); + stdio_mutex.unlock(); } void moveRight() { - setXPosition(getXPosition() + 21); + stdio_mutex.lock(); + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,BLACK); + frog_x=frog_x+6; + + uLCD.filled_rectangle(frog_x,frog_y,frog_x+5,frog_y+5,RED); + stdio_mutex.unlock(); } int getXPosition() {
--- a/main.cpp Sat Oct 29 22:15:03 2016 +0000 +++ b/main.cpp Sun Oct 30 04:39:01 2016 +0000 @@ -7,6 +7,8 @@ #include "Speaker.h" #include "wave_player.h" #include "SDFileSystem.h" + + BusOut mbedleds(LED1,LED2,LED3,LED4); Robot myRobot; Nav_Switch myNav( p21, p22, p23, p24, p25); @@ -14,6 +16,8 @@ AnalogOut DACout(p18); // used to play sound on speaker wave_player waver(&DACout); SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card setup + + //Wiring Set-up: //Speaker: p18 //SD Card: DO=p6,SCK=p7,DI=p5,CS=p8,VCC=Vout,GND=GND @@ -150,6 +154,27 @@ while(1) { mbedleds = ~(myNav & 0x0F); //update leds with nav switch direction inputs if(myNav.fire()) mbedleds = 0x0F; + + // Player Movement checked with navigation switch + if (myNav.left() ) + { + myRobot.moveLeft(); + } + + if (myNav.right()) + { + myRobot.moveRight(); + } + + if (myNav.up()) + { + myRobot.moveForward(); + } + + if (myNav.down()) + { + myRobot.moveBackward(); + } Thread::wait(50); } } @@ -169,7 +194,7 @@ } myRobot.drawFrog(); - Thread thread1(AutoPilot_thread); + //Thread thread1(AutoPilot_thread); Thread thread2(Location_thread); Thread thread3(ThumbStick_thread); Thread thread4(SFX_thread);