[136] | 1 | /* Robot Line Follow
|
---|
| 2 |
|
---|
| 3 | This sketch demonstrates the line following capabilities
|
---|
| 4 | of the Arduino Robot. On the floor, place some black
|
---|
| 5 | electrical tape along the path you wish the robot to follow.
|
---|
| 6 | To indicate a stopping point, place another piece of tape
|
---|
| 7 | perpendicular to the path.
|
---|
| 8 |
|
---|
| 9 | Circuit:
|
---|
| 10 | * Arduino Robot
|
---|
| 11 |
|
---|
| 12 | created 1 May 2013
|
---|
| 13 | by X. Yang
|
---|
| 14 | modified 12 May 2013
|
---|
| 15 | by D. Cuartielles
|
---|
| 16 |
|
---|
| 17 | This example is in the public domain
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | #include <ArduinoRobot.h> // include the robot library
|
---|
| 21 | #include <Wire.h>
|
---|
| 22 | #include <SPI.h>
|
---|
| 23 |
|
---|
| 24 | long timerOrigin; // used for counting elapsed time
|
---|
| 25 |
|
---|
| 26 | void setup() {
|
---|
| 27 | // initialize the Robot, SD card, display, and speaker
|
---|
| 28 | Robot.begin();
|
---|
| 29 | Robot.beginTFT();
|
---|
| 30 | Robot.beginSD();
|
---|
| 31 | Robot.beginSpeaker();
|
---|
| 32 |
|
---|
| 33 | // show the logots on the TFT screen
|
---|
| 34 | Robot.displayLogos();
|
---|
| 35 |
|
---|
| 36 | Robot.drawBMP("lf.bmp", 0, 0); // display background image
|
---|
| 37 |
|
---|
| 38 | Robot.playFile("chase.sqm"); // play a song from the SD card
|
---|
| 39 |
|
---|
| 40 | // add the instructions
|
---|
| 41 | Robot.text("Line Following\n\n place the robot on\n the track and \n see it run", 5, 5);
|
---|
| 42 | Robot.text("Press the middle\n button to start...", 5, 61);
|
---|
| 43 | Robot.waitContinue();
|
---|
| 44 |
|
---|
| 45 | // These are some general values that work for line following
|
---|
| 46 | // uncomment one or the other to see the different behaviors of the robot
|
---|
| 47 | //Robot.lineFollowConfig(14, 9, 50, 10);
|
---|
| 48 | Robot.lineFollowConfig(11, 7, 60, 5);
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | //set the motor board into line-follow mode
|
---|
| 52 | Robot.setMode(MODE_LINE_FOLLOW);
|
---|
| 53 |
|
---|
| 54 | // start
|
---|
| 55 | Robot.fill(255, 255, 255);
|
---|
| 56 | Robot.stroke(255, 255, 255);
|
---|
| 57 | Robot.rect(0, 0, 128, 80); // erase the previous text
|
---|
| 58 | Robot.stroke(0, 0, 0);
|
---|
| 59 | Robot.text("Start", 5, 5);
|
---|
| 60 |
|
---|
| 61 | Robot.stroke(0, 0, 0); // choose color for the text
|
---|
| 62 | Robot.text("Time passed:", 5, 21); // write some text to the screen
|
---|
| 63 |
|
---|
| 64 | timerOrigin = millis(); // keep track of the elapsed time
|
---|
| 65 |
|
---|
| 66 | while (!Robot.isActionDone()) { //wait for the finish signal
|
---|
| 67 | Robot.debugPrint(millis() - timerOrigin, 5, 29); // show how much time has passed
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | Robot.stroke(0, 0, 0);
|
---|
| 71 | Robot.text("Done!", 5, 45);
|
---|
| 72 | }
|
---|
| 73 | void loop() {
|
---|
| 74 | //nothing here, the program only runs once. Reset the robot
|
---|
| 75 | //to do it again!
|
---|
| 76 | }
|
---|