uLCD robot moveable via pushbuttons
Dependencies: 4DGL-uLCD-SE PinDetect mbed
Robot.h@0:327ccd5eafc8, 2016-11-06 (annotated)
- Committer:
- jboettcher
- Date:
- Sun Nov 06 21:57:20 2016 +0000
- Revision:
- 0:327ccd5eafc8
Complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jboettcher | 0:327ccd5eafc8 | 1 | #include <iostream> |
jboettcher | 0:327ccd5eafc8 | 2 | using namespace std; |
jboettcher | 0:327ccd5eafc8 | 3 | |
jboettcher | 0:327ccd5eafc8 | 4 | class Robot |
jboettcher | 0:327ccd5eafc8 | 5 | { |
jboettcher | 0:327ccd5eafc8 | 6 | public: |
jboettcher | 0:327ccd5eafc8 | 7 | void draw() { |
jboettcher | 0:327ccd5eafc8 | 8 | uLCD.circle(xPosition - 8, yPosition - 8, radius, BLACK); |
jboettcher | 0:327ccd5eafc8 | 9 | uLCD.circle(xPosition + 8, yPosition - 8, radius, BLACK); |
jboettcher | 0:327ccd5eafc8 | 10 | uLCD.filled_circle(xPosition - 8, yPosition - 8, 2, BLACK); |
jboettcher | 0:327ccd5eafc8 | 11 | uLCD.filled_circle(xPosition + 8, yPosition - 8, 2, BLACK); } |
jboettcher | 0:327ccd5eafc8 | 12 | void erase() { |
jboettcher | 0:327ccd5eafc8 | 13 | uLCD.filled_rectangle(0, 126, 126, 26, RED); } |
jboettcher | 0:327ccd5eafc8 | 14 | void moveForward(int distance) { |
jboettcher | 0:327ccd5eafc8 | 15 | radius++; } |
jboettcher | 0:327ccd5eafc8 | 16 | void moveBackward(int distance) { |
jboettcher | 0:327ccd5eafc8 | 17 | radius--; } |
jboettcher | 0:327ccd5eafc8 | 18 | void moveLeft(int distance) { |
jboettcher | 0:327ccd5eafc8 | 19 | xPosition--; } |
jboettcher | 0:327ccd5eafc8 | 20 | void moveRight(int distance) { |
jboettcher | 0:327ccd5eafc8 | 21 | xPosition++; } |
jboettcher | 0:327ccd5eafc8 | 22 | Robot() { |
jboettcher | 0:327ccd5eafc8 | 23 | radius = 5; |
jboettcher | 0:327ccd5eafc8 | 24 | xPosition = 63; |
jboettcher | 0:327ccd5eafc8 | 25 | yPosition = 63; |
jboettcher | 0:327ccd5eafc8 | 26 | } |
jboettcher | 0:327ccd5eafc8 | 27 | private: |
jboettcher | 0:327ccd5eafc8 | 28 | int radius; |
jboettcher | 0:327ccd5eafc8 | 29 | int xPosition; |
jboettcher | 0:327ccd5eafc8 | 30 | int yPosition; |
jboettcher | 0:327ccd5eafc8 | 31 | }; |