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: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of 4180_Lab4_v6 by
Robot.h
00001 //robot 00002 class Robot 00003 { 00004 Mutex stdio_mutex; 00005 int FrogX; 00006 int FrogY; 00007 public: 00008 void drawFrog() { 00009 uLCD.filled_rectangle(XPosition-5,YPosition-5,XPosition+5,YPosition+5,RED); 00010 } 00011 00012 void drawDeadFrog() { 00013 uLCD.filled_rectangle(XPosition-5,YPosition-5,XPosition+5,YPosition+5,WHITE); 00014 } 00015 00016 void drawOutline() { 00017 uLCD.line(0, 0 , 0, 127, BLACK); 00018 uLCD.line(0, 0 , 127, 0, BLACK); 00019 uLCD.line(127, 127 , 0, 127, BLACK); 00020 uLCD.line(127, 127 , 127, 0, BLACK); 00021 } 00022 00023 void drawGrass(int Xp,int Yp) { 00024 uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,GREEN); 00025 } 00026 00027 void drawBar(int Xp,int Yp) { 00028 uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,BLACK); 00029 } 00030 00031 void drawRoad(int Xp,int Yp) { 00032 uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,BLACK); 00033 uLCD.filled_rectangle(Xp-2,Yp-1,Xp+2,Yp+1,WHITE); 00034 } 00035 00036 void drawCar1(int Position1, int CarWidth) { 00037 //stdio_mutex.lock(); 00038 uLCD.filled_rectangle(Position1-CarWidth,95-4,Position1+CarWidth,95+4,BLUE); 00039 //stdio_mutex.unlock(); 00040 } 00041 00042 void drawCar2(int Position2, int CarWidth) { 00043 //stdio_mutex.lock(); 00044 uLCD.filled_rectangle(Position2-CarWidth,52-4,Position2+CarWidth,52+4,RED); 00045 //stdio_mutex.unlock(); 00046 } 00047 00048 void drawWater(int Xp,int Yp) { 00049 uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,BLUE); 00050 if(Xp == 11 || Xp == 53 || Xp == 95){ 00051 uLCD.filled_rectangle(Xp-6,Yp-6,Xp+6,Yp+6,GREEN); 00052 } 00053 } 00054 00055 void drawDrown1() { 00056 uLCD.filled_rectangle(XPosition-10,YPosition-10,XPosition+10,YPosition+10,BLUE); 00057 uLCD.filled_rectangle(XPosition-4,YPosition-4,XPosition+4,YPosition+4,RED); 00058 uLCD.circle(XPosition, YPosition , 2, WHITE); 00059 } 00060 void drawDrown2() { 00061 uLCD.filled_rectangle(XPosition-10,YPosition-10,XPosition+10,YPosition+10,BLUE); 00062 uLCD.filled_rectangle(XPosition-3,YPosition-3,XPosition+3,YPosition+3,RED); 00063 uLCD.circle(XPosition, YPosition, 3, WHITE); 00064 } 00065 void drawDrown3() { 00066 uLCD.filled_rectangle(XPosition-10,YPosition-10,XPosition+10,YPosition+10,BLUE); 00067 uLCD.filled_rectangle(XPosition-1,YPosition-1,XPosition+1,YPosition+1,RED); 00068 uLCD.circle(XPosition, YPosition, 4 , WHITE); 00069 } 00070 void drawDrown4() { 00071 uLCD.filled_rectangle(XPosition-10,YPosition-10,XPosition+10,YPosition+10,BLUE); 00072 uLCD.circle(XPosition, YPosition, 5 , WHITE); 00073 uLCD.circle(XPosition, YPosition, 2 , WHITE); 00074 } 00075 void drawDrown5() { 00076 uLCD.filled_rectangle(XPosition-10,YPosition-10,XPosition+10,YPosition+10,BLUE); 00077 } 00078 00079 void drawHelper(int Xp,int Yp) { 00080 if(Yp == 11) { 00081 drawBar(Xp,Yp); //Row 1 00082 } 00083 if(Yp == 32){ 00084 drawGrass(Xp,Yp); //Row 2 00085 } 00086 if(Yp == 53){ 00087 drawRoad(Xp,Yp); //Row 3 00088 } 00089 if(Yp == 74){ 00090 drawWater(Xp,Yp); //Row 4 00091 } 00092 if(Yp == 95){ 00093 drawRoad(Xp,Yp); //Row 5 00094 } 00095 if(Yp == 116){ 00096 drawGrass(Xp,Yp); //Row 6 00097 } 00098 } 00099 00100 void drawEraser() { 00101 drawHelper(XPosition,YPosition); 00102 } 00103 00104 void moveForward() { 00105 drawHelper(XPosition,YPosition); 00106 setYPosition(getYPosition() - 21); 00107 drawFrog(); 00108 } 00109 void moveBackward() { 00110 FrogY = getYPosition(); 00111 if(FrogY > 11){ 00112 drawHelper(XPosition,YPosition); 00113 setYPosition(FrogY + 21); 00114 drawFrog(); 00115 } 00116 } 00117 void moveLeft() { 00118 FrogX = getXPosition(); 00119 if(FrogX > 11){ 00120 drawHelper(XPosition,YPosition); 00121 setXPosition(FrogX - 21); 00122 drawFrog(); 00123 } 00124 } 00125 void moveRight() { 00126 FrogX = getXPosition(); 00127 if(FrogX < 116){ 00128 drawHelper(XPosition,YPosition); 00129 setXPosition(FrogX + 21); 00130 drawFrog(); 00131 } 00132 } 00133 00134 int getXPosition() { 00135 return XPosition; 00136 } 00137 int getYPosition() { 00138 return YPosition; 00139 } 00140 00141 void setXPosition(int x) { 00142 XPosition=x; 00143 } 00144 void setYPosition(int y) { 00145 YPosition=y; 00146 } 00147 00148 Robot() 00149 { 00150 XPosition = 53; 00151 YPosition = 116; 00152 } 00153 private: 00154 00155 int XPosition; 00156 int YPosition; 00157 };
Generated on Sat Jul 16 2022 06:57:06 by
1.7.2
