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 mbed-rtos mbed
Revision 0:973e6eca2102, committed 2016-10-29
- Comitter:
- swilliams346
- Date:
- Sat Oct 29 22:10:24 2016 +0000
- Commit message:
- ERICK
Changed in this revision
diff -r 000000000000 -r 973e6eca2102 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Sat Oct 29 22:10:24 2016 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r 973e6eca2102 Nav_Switch.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Nav_Switch.h Sat Oct 29 22:10:24 2016 +0000
@@ -0,0 +1,55 @@
+class Nav_Switch
+{
+public:
+ Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire);
+ int read();
+//boolean functions to test each switch
+ bool up();
+ bool down();
+ bool left();
+ bool right();
+ bool fire();
+//automatic read on RHS
+ operator int ();
+//index to any switch array style
+ bool operator[](int index) {
+ return _pins[index];
+ };
+private:
+ BusIn _pins;
+
+};
+Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire):
+ _pins(up, down, left, right, fire)
+{
+ _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise
+ wait(0.001); //delays just a bit for pullups to pull inputs high
+}
+inline bool Nav_Switch::up()
+{
+ return !(_pins[0]);
+}
+inline bool Nav_Switch::down()
+{
+ return !(_pins[1]);
+}
+inline bool Nav_Switch::left()
+{
+ return !(_pins[2]);
+}
+inline bool Nav_Switch::right()
+{
+ return !(_pins[3]);
+}
+inline bool Nav_Switch::fire()
+{
+ return !(_pins[4]);
+}
+inline int Nav_Switch::read()
+{
+ return _pins.read();
+}
+inline Nav_Switch::operator int ()
+{
+ return _pins.read();
+}
\ No newline at end of file
diff -r 000000000000 -r 973e6eca2102 PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Sat Oct 29 22:10:24 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r 973e6eca2102 Robot.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Robot.h Sat Oct 29 22:10:24 2016 +0000
@@ -0,0 +1,97 @@
+//robot
+class Robot
+{
+public:
+ void drawFrog() {
+ uLCD.filled_rectangle(XPosition-5,YPosition-5,XPosition+5,YPosition+5,RED);
+ }
+
+ void drawOutline() {
+ uLCD.line(0, 0 , 0, 127, BLACK);
+ uLCD.line(0, 0 , 127, 0, BLACK);
+ uLCD.line(127, 127 , 0, 127, BLACK);
+ uLCD.line(127, 127 , 127, 0, BLACK);
+ }
+
+ void drawGrass(int Xp,int Yp) {
+ uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,GREEN);
+ }
+
+ void drawBar(int Xp,int Yp) {
+ uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,BLACK);
+ }
+
+ void drawRoad(int Xp,int Yp) {
+ uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,BLACK);
+ uLCD.filled_rectangle(Xp-2,Yp-1,Xp+2,Yp+1,WHITE);
+ }
+
+ void drawWater(int Xp,int Yp) {
+ uLCD.filled_rectangle(Xp-10,Yp-10,Xp+10,Yp+10,BLUE);
+ if(Xp == 11 || Xp == 53 || Xp == 95){
+ uLCD.filled_rectangle(Xp-6,Yp-6,Xp+6,Yp+6,GREEN);
+ }
+ }
+
+ void drawHelper(int Xp,int Yp) {
+ if(Yp == 11) {
+ drawBar(Xp,Yp); //Row 1
+ }
+ if(Yp == 32){
+ drawGrass(Xp,Yp); //Row 2
+ }
+ if(Yp == 53){
+ drawRoad(Xp,Yp); //Row 3
+ }
+ if(Yp == 74){
+ drawWater(Xp,Yp); //Row 4
+ }
+ if(Yp == 95){
+ drawRoad(Xp,Yp); //Row 5
+ }
+ if(Yp == 116){
+ drawGrass(Xp,Yp); //Row 6
+ }
+ }
+
+ void drawEraser() {
+ drawHelper(XPosition,YPosition);
+ }
+
+ void moveForward() {
+ setYPosition(getYPosition() - 21);
+ }
+ void moveBackward() {
+ setYPosition(getYPosition() + 21);
+ }
+ void moveLeft() {
+ setXPosition(getXPosition() - 21);
+ }
+ void moveRight() {
+ setXPosition(getXPosition() + 21);
+ }
+
+ int getXPosition() {
+ return XPosition;
+ }
+ int getYPosition() {
+ return YPosition;
+ }
+
+ void setXPosition(int x) {
+ XPosition=x;
+ }
+ void setYPosition(int y) {
+ YPosition=y;
+ }
+
+ Robot()
+ {
+ XPosition = 95;
+ YPosition = 116;
+ }
+private:
+
+ int XPosition;
+ int YPosition;
+ };
diff -r 000000000000 -r 973e6eca2102 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Oct 29 22:10:24 2016 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "uLCD_4DGL.h"
+#include "rtos.h"
+uLCD_4DGL uLCD(p28, p27, p30);
+#include "Robot.h"
+#include "Nav_Switch.h"
+BusOut mbedleds(LED1,LED2,LED3,LED4);
+Robot myRobot;
+Nav_Switch myNav( p21, p22, p23, p24, p25);
+
+int i = 11;
+int j = 11;
+int C1 = 11;
+int C2 = 32;
+int C3 = 53;
+int C4 = 74;
+int C5 = 95;
+int C6 = 116;
+
+int main()
+{
+ //Initialize Background
+ uLCD.filled_rectangle(0, 0 , 127, 127, RED);
+ myRobot.drawOutline();
+ while(i <= 116){
+ while(j <= 116){
+ myRobot.drawHelper(i,j);
+ j = j + 21;
+ }
+ j = 11;
+ i = i + 21;
+ }
+ myRobot.drawFrog();
+
+ //Auto-pilot Testing
+ wait(1);
+ myRobot.drawEraser();
+ myRobot.moveForward();
+ myRobot.drawFrog();
+ wait(1);
+ myRobot.drawEraser();
+ myRobot.moveForward();
+ myRobot.drawFrog();
+ wait(1);
+ myRobot.drawEraser();
+ myRobot.moveLeft();
+ myRobot.drawFrog();
+ wait(1);
+ myRobot.drawEraser();
+ myRobot.moveBackward();
+ myRobot.drawFrog();
+
+ //Begin Processes
+ while(1) {
+ mbedleds = ~(myNav & 0x0F); //update leds with nav switch direction inputs
+ if(myNav.fire()) mbedleds = 0x0F;
+ wait(0.02);
+ }
+}
diff -r 000000000000 -r 973e6eca2102 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sat Oct 29 22:10:24 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#3da5f554d8bf
diff -r 000000000000 -r 973e6eca2102 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Oct 29 22:10:24 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/2241e3a39974 \ No newline at end of file