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