So I worked on the entertainment bot idea and this is the first code that I came up with. As I am posting these codes in order that I worked on them, my current entertainment bot tweak will be posted in a few weeks time, as now I have a touch and a sound sensor which really helps 🙂 🙂
The idea with this code was to program Sparki to act like a generic entertainment robot with silly dances, random movements, tune playing and following hand code.
This is the code:
#include <Sparki.h> // include the sparki library void setup() { float lightLeft = 0; float lightCenter = 0; float lightRight = 0; float threshold = 800; float edgeLeft = 0; float edgeRight = 0; sparki.clearLCD(); // wipe the LCD clear sparki.drawString(40, 4, "HELLO"); sparki.updateLCD(); // put the drawings on the screen delay(1000); sparki.moveLeft(30); sparki.moveRight(30); delay(1000); sparki.beep(640, 200); delay(200); sparki.beep(440, 200); delay(100); while(true) { lightLeft = sparki.lightLeft(); lightCenter = sparki.lightCenter(); lightRight = sparki.lightRight(); edgeLeft = sparki.edgeLeft(); edgeRight = sparki.edgeRight(); sparki.servo(0); sparki.RGB(0,220,0); if(((lightCenter>lightLeft)&&(lightRight>lightLeft))) { delay(400); sparki.beep(840, 300); sparki.moveForward(3); sparki.moveRight(40); sparki.beep(440, 500); sparki.RGB(0,250,0); sparki.moveLeft(90); sparki.moveForward(3); sparki.beep(640, 200); delay(200); sparki.beep(740, 200); sparki.moveBackward(3); sparki.moveForward(5); sparki.RGB(220,0,0); sparki.beep(340, 400); delay(200); sparki.beep(640, 400); sparki.moveRight(90); sparki.moveBackward(5); sparki.beep(540, 400); sparki.RGB(0,0,220); } else { delay(1000); } if(((lightLeft>lightRight)&&(lightCenter>lightRight))) { delay(400); sparki.beep(840, 400); delay(200); sparki.beep(640, 400); delay(200); sparki.beep(440, 400); delay(200); sparki.beep(340, 400); delay(200); sparki.beep(640, 800); delay(200); sparki.beep(440, 800); delay(200); sparki.beep(340, 400); delay(200); sparki.beep(440, 400); delay(200); sparki.beep(640, 400); delay(200); } else { delay(1000); } if(((edgeLeft<threshold)&&(sparki.ping()>10))) { sparki.RGB(220,0,0); sparki.beep(840, 400); sparki.moveLeft(90); sparki.beep(440, 200); sparki.moveRight(90); sparki.beep(340, 200); delay(100); sparki.beep(540, 200); sparki.RGB(0,0,220); sparki.beep(440, 400); sparki.moveForward(5); delay(200); sparki.beep(640, 400); delay(200); sparki.beep(740, 500); sparki.moveBackward(5); delay(200); } else { } if(((edgeRight<threshold)&&(sparki.ping()>10))) { sparki.beep(740, 600); delay(400); sparki.beep(540, 400); delay(400); sparki.beep(540, 200); delay(200); sparki.beep(440, 200); delay(200); sparki.beep(640, 400); delay(400); sparki.beep(740, 200); delay(400); sparki.beep(740, 200); } else { } sparki.servo(0); delay(1000); if((sparki.ping()<10)) { sparki.moveForward(7); sparki.servo(90); delay(1000); if((sparki.ping()<10)) { sparki.moveRight(90); sparki.moveForward(7); sparki.servo(-(90)); delay(1000); if((sparki.ping()<10)) { sparki.moveLeft(90); sparki.moveForward(7); } else { sparki.moveBackward(5); sparki.RGB(0,0,220); sparki.moveLeft(180); } } else { sparki.servo(-(90)); delay(1000); if((sparki.ping()<10)) { sparki.moveLeft(90); sparki.moveForward(7); } else { } } } else { sparki.servo(90); delay(1000); if((sparki.ping()<10)) { sparki.moveRight(90); sparki.moveForward(7); } else { sparki.servo(-(90)); delay(1000); if((sparki.ping()<10)) { sparki.moveLeft(90); sparki.moveForward(7); } else { sparki.moveForward(5); sparki.RGB(0,0,220); sparki.moveRight(90); sparki.moveLeft(90); } } } delay(1000); } } void loop() { }
Here is a video of the code in action:
https://drive.google.com/file/d/0B6y9ITteBcqLR2FwNkoweU1pOVk/view?usp=sharing
Let me know what you think 🙂 🙂
[…] I will post my first edit of the remote control code which I really liked and links to the entertainment bot code I uploaded a while […]
LikeLiked by 1 person
[…] wanted to use the remote control to flit between modes for Sparki so I took the ideas from my entertainment bot code and some of my other favourite aspects of Sparki and put the simplest versions of these codes onto […]
LikeLike