added arduino, modified build
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
/* Robot Logo
|
||||
|
||||
This sketch demonstrates basic movement of the Robot.
|
||||
When the sketch starts, press the on-board buttons to tell
|
||||
the robot how to move. Pressing the middle button will
|
||||
save the pattern, and the robot will follow accordingly.
|
||||
You can record up to 20 commands. The robot will move for
|
||||
one second per command.
|
||||
|
||||
This example uses images on an SD card. It looks for
|
||||
files named "lg0.bmp" and "lg1.bmp" and draws them on the
|
||||
screen.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h> // include the robot library
|
||||
#include <Wire.h>
|
||||
|
||||
int commands[20]; // array for storing commands
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, and display
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
|
||||
// draw "lg0.bmp" and "lg1.bmp" on the screen
|
||||
Robot.displayLogos();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Robot.drawBMP("intro.bmp", 0, 0); //display background image
|
||||
|
||||
iniCommands(); // remove commands from the array
|
||||
addCommands(); // add commands to the array
|
||||
|
||||
delay(1000); // wait for a second
|
||||
|
||||
executeCommands(); // follow orders
|
||||
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Done!", 5, 103); // write some text to the display
|
||||
delay(1500); // wait for a moment
|
||||
}
|
||||
|
||||
// empty the commands array
|
||||
void iniCommands() {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
commands[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// add commands to the array
|
||||
void addCommands() {
|
||||
Robot.stroke(0, 0, 0);
|
||||
// display text on the screen
|
||||
Robot.text("1. Press buttons to\n add commands.\n\n 2. Middle to finish.", 5, 5);
|
||||
|
||||
// read the buttons' state
|
||||
for (int i = 0; i < 20;) { //max 20 commands
|
||||
int key = Robot.keyboardRead();
|
||||
if (key == BUTTON_MIDDLE) { //finish input
|
||||
break;
|
||||
} else if (key == BUTTON_NONE) { //if no button is pressed
|
||||
continue;
|
||||
}
|
||||
commands[i] = key; // save the button to the array
|
||||
PrintCommandI(i, 46); // print the command on the screen
|
||||
delay(100);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// run through the array and move the robot
|
||||
void executeCommands() {
|
||||
// print status to the screen
|
||||
Robot.text("Excuting...", 5, 70);
|
||||
|
||||
// read through the array and move accordingly
|
||||
for (int i = 0; i < 20; i++) {
|
||||
switch (commands[i]) {
|
||||
case BUTTON_LEFT:
|
||||
Robot.turn(-90);
|
||||
break;
|
||||
case BUTTON_RIGHT:
|
||||
Robot.turn(90);
|
||||
break;
|
||||
case BUTTON_UP:
|
||||
Robot.motorsWrite(255, 255);
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
Robot.motorsWrite(-255, -255);
|
||||
break;
|
||||
case BUTTON_NONE:
|
||||
return;
|
||||
}
|
||||
// print the current command to the screen
|
||||
Robot.stroke(255, 0, 0);
|
||||
PrintCommandI(i, 86);
|
||||
delay(1000);
|
||||
|
||||
// stop moving for a second
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
// convert the button press to a single character
|
||||
char keyToChar(int key) {
|
||||
switch (key) {
|
||||
case BUTTON_LEFT:
|
||||
return '<';
|
||||
case BUTTON_RIGHT:
|
||||
return '>';
|
||||
case BUTTON_UP:
|
||||
return '^';
|
||||
case BUTTON_DOWN:
|
||||
return 'v';
|
||||
}
|
||||
}
|
||||
|
||||
// display a command
|
||||
void PrintCommandI(int i, int originY) {
|
||||
Robot.text(keyToChar(commands[i]), i % 14 * 8 + 5, i / 14 * 10 + originY);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* Robot Line Follow
|
||||
|
||||
This sketch demonstrates the line following capabilities
|
||||
of the Arduino Robot. On the floor, place some black
|
||||
electrical tape along the path you wish the robot to follow.
|
||||
To indicate a stopping point, place another piece of tape
|
||||
perpendicular to the path.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h> // include the robot library
|
||||
#include <Wire.h>
|
||||
|
||||
long timerOrigin; // used for counting elapsed time
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
Robot.beginSpeaker();
|
||||
|
||||
// show the logots on the TFT screen
|
||||
Robot.displayLogos();
|
||||
|
||||
Robot.drawBMP("lf.bmp", 0, 0); // display background image
|
||||
|
||||
Robot.playFile("chase.sqm"); // play a song from the SD card
|
||||
|
||||
// add the instructions
|
||||
Robot.text("Line Following\n\n place the robot on\n the track and \n see it run", 5, 5);
|
||||
Robot.text("Press the middle\n button to start...", 5, 61);
|
||||
Robot.waitContinue();
|
||||
|
||||
// These are some general values that work for line following
|
||||
// uncomment one or the other to see the different behaviors of the robot
|
||||
//Robot.lineFollowConfig(14, 9, 50, 10);
|
||||
Robot.lineFollowConfig(11, 7, 60, 5);
|
||||
|
||||
|
||||
//set the motor board into line-follow mode
|
||||
Robot.setMode(MODE_LINE_FOLLOW);
|
||||
|
||||
// start
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.rect(0, 0, 128, 80); // erase the previous text
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Start", 5, 5);
|
||||
|
||||
Robot.stroke(0, 0, 0); // choose color for the text
|
||||
Robot.text("Time passed:", 5, 21); // write some text to the screen
|
||||
|
||||
timerOrigin = millis(); // keep track of the elapsed time
|
||||
|
||||
while (!Robot.isActionDone()) { //wait for the finish signal
|
||||
Robot.debugPrint(millis() - timerOrigin, 5, 29); // show how much time has passed
|
||||
}
|
||||
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Done!", 5, 45);
|
||||
}
|
||||
void loop() {
|
||||
//nothing here, the program only runs once. Reset the robot
|
||||
//to do it again!
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/* Disco Bot
|
||||
|
||||
This sketch shows you how to use the melody playing
|
||||
feature of the robot, with some really cool 8-bit music.
|
||||
Music will play when the robot is turned on, and it
|
||||
will show you some dance moves.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h> // include the robot library
|
||||
#include <Wire.h>
|
||||
|
||||
/* Dancing steps:
|
||||
S: stop
|
||||
L: turn left
|
||||
R: turn right
|
||||
F: go forward
|
||||
B: go backwards
|
||||
|
||||
The number after each command determines how long
|
||||
each step lasts. Each number is 1/2 second long.
|
||||
|
||||
The "\0" indicates end of string
|
||||
*/
|
||||
char danceScript[] = "S4L1R1S2F1B1S1\0";
|
||||
|
||||
int currentScript = 0; // what step are we at
|
||||
|
||||
int currentSong = 0; // keep track of the current song
|
||||
static const int SONGS_COUNT = 3; // number of songs
|
||||
|
||||
// an array to hold the songs
|
||||
char musics[][11] = {
|
||||
"melody.sqm",
|
||||
"menu.sqm",
|
||||
"chase.sqm",
|
||||
};
|
||||
|
||||
// variables for non-blocking delay
|
||||
long waitFrom;
|
||||
long waitTime = 0;
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Robot.begin();
|
||||
Robot.beginSpeaker();
|
||||
Robot.beginSD();
|
||||
Robot.beginTFT();
|
||||
|
||||
// draw "lg0.bmp" and "lg1.bmp" on the screen
|
||||
Robot.displayLogos();
|
||||
|
||||
// Print instructions to the screen
|
||||
Robot.text("1. Use left and\n right key to switch\n song", 5, 5);
|
||||
Robot.text("2. Put robot on the\n ground to dance", 5, 33);
|
||||
|
||||
// wait for a few soconds
|
||||
delay(3000);
|
||||
|
||||
setInterface(); // display the current song
|
||||
play(0); //play the first song in the array
|
||||
|
||||
resetWait(); //Initialize non-blocking delay
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the butttons on the robot
|
||||
int key = Robot.keyboardRead();
|
||||
|
||||
// Right/left buttons play next/previous song
|
||||
switch (key) {
|
||||
case BUTTON_UP:
|
||||
case BUTTON_LEFT:
|
||||
play(-1); //play previous song
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
case BUTTON_RIGHT:
|
||||
play(1); //play next song
|
||||
break;
|
||||
}
|
||||
|
||||
// dance!
|
||||
runScript();
|
||||
}
|
||||
|
||||
// Dancing function
|
||||
void runScript() {
|
||||
if (!waiting()) { // if the previous instructions have finished
|
||||
// get the next 2 commands (direction and duration)
|
||||
parseCommand(danceScript[currentScript], danceScript[currentScript + 1]);
|
||||
currentScript += 2;
|
||||
if (danceScript[currentScript] == '\0') { // at the end of the array
|
||||
currentScript = 0; // start again at the beginning
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// instead of delay, use this timer
|
||||
boolean waiting() {
|
||||
if (millis() - waitFrom >= waitTime) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// how long to wait
|
||||
void wait(long t) {
|
||||
resetWait();
|
||||
waitTime = t;
|
||||
}
|
||||
|
||||
// reset the timer
|
||||
void resetWait() {
|
||||
waitFrom = millis();
|
||||
}
|
||||
|
||||
// read the direction and dirstion of the steps
|
||||
void parseCommand(char dir, char duration) {
|
||||
//convert the scripts to action
|
||||
switch (dir) {
|
||||
case 'L':
|
||||
Robot.motorsWrite(-255, 255);
|
||||
break;
|
||||
case 'R':
|
||||
Robot.motorsWrite(255, -255);
|
||||
break;
|
||||
case 'F':
|
||||
Robot.motorsWrite(255, 255);
|
||||
break;
|
||||
case 'B':
|
||||
Robot.motorsWrite(-255, -255);
|
||||
break;
|
||||
case 'S':
|
||||
Robot.motorsStop();
|
||||
break;
|
||||
}
|
||||
//You can change "500" to change the pace of dancing
|
||||
wait(500 * (duration - '0'));
|
||||
}
|
||||
|
||||
// display the song
|
||||
void setInterface() {
|
||||
Robot.clearScreen();
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text(musics[0], 0, 0);
|
||||
}
|
||||
|
||||
// display the next song
|
||||
void select(int seq, boolean onOff) {
|
||||
if (onOff) { //select
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text(musics[seq], 0, 0);
|
||||
} else { //deselect
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.text(musics[seq], 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// play the slected song
|
||||
void play(int seq) {
|
||||
select(currentSong, false);
|
||||
if (currentSong <= 0 && seq == -1) { //previous of 1st song?
|
||||
currentSong = SONGS_COUNT - 1; //go to last song
|
||||
} else if (currentSong >= SONGS_COUNT - 1 && seq == 1) { //next of last?
|
||||
currentSong = 0; //go to 1st song
|
||||
} else {
|
||||
currentSong += seq; //next song
|
||||
}
|
||||
Robot.stopPlayFile();
|
||||
Robot.playFile(musics[currentSong]);
|
||||
select(currentSong, true); //display the current song
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Robot Compass
|
||||
|
||||
The robot has an on-board compass module, with
|
||||
which it can tell the direction the robot is
|
||||
facing. This sketch will make sure the robot
|
||||
goes towards a certain direction.
|
||||
|
||||
Beware, magnets will interfere with the compass
|
||||
readings.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
// include the robot library
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
int speedLeft;
|
||||
int speedRight;
|
||||
int compassValue;
|
||||
int direc = 180; //Direction the robot is heading
|
||||
|
||||
void setup() {
|
||||
// initialize the modules
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
Robot.displayLogos();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the compass orientation
|
||||
compassValue = Robot.compassRead();
|
||||
|
||||
// how many degrees are we off
|
||||
int diff = compassValue - direc;
|
||||
|
||||
// modify degress
|
||||
if (diff > 180) {
|
||||
diff = -360 + diff;
|
||||
} else if (diff < -180) {
|
||||
diff = 360 + diff;
|
||||
}
|
||||
|
||||
// Make the robot turn to its proper orientation
|
||||
diff = map(diff, -180, 180, -255, 255);
|
||||
|
||||
if (diff > 0) {
|
||||
// keep the right wheel spinning,
|
||||
// change the speed of the left wheel
|
||||
speedLeft = 255 - diff;
|
||||
speedRight = 255;
|
||||
} else {
|
||||
// keep the right left spinning,
|
||||
// change the speed of the left wheel
|
||||
speedLeft = 255;
|
||||
speedRight = 255 + diff;
|
||||
}
|
||||
// write out to the motors
|
||||
Robot.motorsWrite(speedLeft, speedRight);
|
||||
|
||||
// draw the orientation on the screen
|
||||
Robot.drawCompass(compassValue);
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* Robot Inputs
|
||||
|
||||
This sketch shows you how to use the on-board
|
||||
potentiometer and buttons as inputs.
|
||||
|
||||
Turning the potentiometer draws a clock-shaped
|
||||
circle. The up and down buttons change the pitch,
|
||||
while the left and right buttons change the tempo.
|
||||
The middle button resets tempo and pitch.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// default tempo and pitch of the music
|
||||
int tempo = 60;
|
||||
int pitch = 1000;
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, speaker, and display
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSpeaker();
|
||||
Robot.beginSD();
|
||||
|
||||
// draw "lg0.bmp" and "lg1.bmp" on the screen
|
||||
Robot.displayLogos();
|
||||
|
||||
// play a sound file
|
||||
Robot.playFile("Melody.sqm");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the value of the buttons
|
||||
keyDown(Robot.keyboardRead());
|
||||
|
||||
// check the value of the pot
|
||||
drawKnob(Robot.knobRead());
|
||||
}
|
||||
|
||||
// Draw the basic interface
|
||||
void renderUI() {
|
||||
//fill the buttons blank
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.rect(53, 58, 13, 13); // left
|
||||
Robot.rect(93, 58, 13, 13); // right
|
||||
Robot.rect(73, 38, 13, 13); // up
|
||||
Robot.circle(79, 64, 6); // middle
|
||||
Robot.rect(73, 78, 13, 13); // down
|
||||
|
||||
//draw the knob
|
||||
Robot.noFill();
|
||||
Robot.circle(26, 116, 17); // knob
|
||||
|
||||
//draw the vertical bargraph
|
||||
int fullPart = map(pitch, 200, 2000, 0, 58); //length of filled bargraph
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.rect(21, 30, 13, 58 - fullPart);
|
||||
Robot.fill(0, 0, 255);
|
||||
Robot.rect(21, 88 - fullPart, 13, fullPart); //58-fullPart+30
|
||||
|
||||
//draw the horizontal bargraph
|
||||
fullPart = map(tempo, 20, 100, 0, 58); // length of filled bargraph
|
||||
Robot.fill(255, 190, 0);
|
||||
Robot.rect(53, 110, fullPart, 13);
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.rect(53 + fullPart, 110, 58 - fullPart, 13);
|
||||
}
|
||||
|
||||
void keyDown(int keyCode) {
|
||||
// use a static int so it is persistent over time
|
||||
static int oldKey;
|
||||
switch (keyCode) {
|
||||
case BUTTON_LEFT:
|
||||
//left button pressed, reduces tempo
|
||||
tempo -= 5;
|
||||
if (tempo < 20) {
|
||||
tempo = 20; //lowest tempo 20
|
||||
}
|
||||
Robot.fill(255, 190, 0);
|
||||
|
||||
Robot.rect(53, 58, 13, 13);
|
||||
break;
|
||||
case BUTTON_RIGHT:
|
||||
//right button pressed, increases tempo
|
||||
tempo += 5;
|
||||
if (tempo > 100) {
|
||||
tempo = 100; //highest tempo 100
|
||||
}
|
||||
Robot.fill(255, 190, 0);
|
||||
Robot.rect(93, 58, 13, 13);
|
||||
break;
|
||||
case BUTTON_UP:
|
||||
//up button pressed, increases pitch
|
||||
pitch += 120;
|
||||
if (pitch > 2000) {
|
||||
pitch = 2000;
|
||||
}
|
||||
Robot.fill(0, 0, 255);
|
||||
|
||||
Robot.rect(73, 38, 13, 13);
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
//down button pressed, reduces pitch
|
||||
pitch -= 120;
|
||||
if (pitch < 200) {
|
||||
pitch = 200;
|
||||
}
|
||||
Robot.fill(0, 0, 255);
|
||||
|
||||
Robot.rect(73, 78, 13, 13);
|
||||
break;
|
||||
case BUTTON_MIDDLE:
|
||||
//middle button pressed, resets tempo and pitch
|
||||
tempo = 60;
|
||||
pitch = 1000;
|
||||
Robot.fill(160, 160, 160);
|
||||
|
||||
Robot.circle(79, 64, 6);
|
||||
break;
|
||||
case BUTTON_NONE:
|
||||
//Only when the keys are released(thus BUTTON_NONE is
|
||||
//encountered the first time), the interface will be
|
||||
//re-drawn.
|
||||
if (oldKey != BUTTON_NONE) {
|
||||
renderUI();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (oldKey != keyCode) {
|
||||
// change the song's tempo
|
||||
Robot.tempoWrite(tempo);
|
||||
// change the song's pitch
|
||||
Robot.tuneWrite(float(pitch / 1000.0));
|
||||
}
|
||||
oldKey = keyCode;
|
||||
}
|
||||
|
||||
//Draw a circle according to value
|
||||
//of the knob.
|
||||
void drawKnob(int val) {
|
||||
static int val_old;
|
||||
int r = map(val, 0, 1023, 1, 15);
|
||||
|
||||
//Only updates when the
|
||||
//value changes.
|
||||
if (val_old != r) {
|
||||
Robot.noFill();
|
||||
|
||||
//erase the old circle
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.circle(26, 116, r + 1);
|
||||
|
||||
//draw the new circle
|
||||
Robot.stroke(255, 0, 255);
|
||||
Robot.circle(26, 116, r);
|
||||
|
||||
Robot.stroke(0, 0, 0);
|
||||
|
||||
val_old = r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* 6 Wheel Calibration
|
||||
*
|
||||
* Use this sketch to calibrate the wheels in your robot.
|
||||
* Your robot should drive as straight as possible when
|
||||
* putting both motors at the same speed.
|
||||
*
|
||||
* Run the software and follow the on-screen instructions.
|
||||
* Use the trimmer on the bottom board to make sure the
|
||||
* robot is working at its best!
|
||||
*
|
||||
* (c) 2013 X. Yang
|
||||
*/
|
||||
#include "scripts_library.h"
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
|
||||
Robot.setTextWrap(false);
|
||||
Robot.displayLogos();
|
||||
|
||||
writeAllScripts();
|
||||
|
||||
}
|
||||
void loop() {
|
||||
int val = map(Robot.knobRead(), 0, 1023, -255, 255);
|
||||
Serial.println(val);
|
||||
Robot.motorsWrite(val, val);
|
||||
|
||||
int WC = map(Robot.trimRead(), 0, 1023, -20, 20);
|
||||
Robot.debugPrint(WC, 108, 149);
|
||||
delay(40);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include <ArduinoRobot.h>
|
||||
|
||||
const char script1[] PROGMEM="Wheel Calibration\n";
|
||||
const char script2[] PROGMEM="1. Put Robot on a flat surface\n";
|
||||
const char script3[] PROGMEM="2. Adjust speed with the knob on top\n";
|
||||
const char script4[] PROGMEM="3. If robot goes straight, it's done\n";
|
||||
const char script5[] PROGMEM="4. Use screwdriver on the trim on bottom\n";
|
||||
const char script6[] PROGMEM="Robot turns left, screw it clockwise;\n";
|
||||
const char script7[] PROGMEM="Turns right, screw it ct-colockwise;\n";
|
||||
const char script8[] PROGMEM="5. Repeat 4 until going straight\n";
|
||||
|
||||
char buffer[42];//must be longer than text
|
||||
|
||||
const char * const scripts[] PROGMEM = {
|
||||
script1,
|
||||
script2,
|
||||
script3,
|
||||
script4,
|
||||
script5,
|
||||
script6,
|
||||
script7,
|
||||
script8,
|
||||
};
|
||||
|
||||
void getPGMtext(int seq){
|
||||
strcpy_P(buffer,(char*)pgm_read_word(&(scripts[seq])));
|
||||
}
|
||||
|
||||
void writePGMtext(int seq){
|
||||
getPGMtext(seq);
|
||||
Robot.print(buffer);
|
||||
}
|
||||
|
||||
void writeScript(int seq){
|
||||
writePGMtext(seq);
|
||||
}
|
||||
|
||||
void writeAllScripts(){
|
||||
for(int i=0;i<8;i++){
|
||||
writeScript(i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/* Runaway Robot
|
||||
|
||||
Play tag with your robot! With an ultrasonic
|
||||
distance sensor, it's capable of detecting and avoiding
|
||||
obstacles, never bumping into walls again!
|
||||
|
||||
You'll need to attach an untrasonic range finder to M1.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
* US range finder like Maxbotix EZ10, with analog output
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
// include the robot library
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
int sensorPin = M1; // pin is used by the sensor
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, and display
|
||||
Serial.begin(9600);
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
Robot.displayLogos();
|
||||
|
||||
// draw a face on the LCD screen
|
||||
setFace(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// If the robot is blocked, turn until free
|
||||
while (getDistance() < 40) { // If an obstacle is less than 20cm away
|
||||
setFace(false); //shows an unhappy face
|
||||
Robot.motorsStop(); // stop the motors
|
||||
delay(1000); // wait for a moment
|
||||
Robot.turn(90); // turn to the right and try again
|
||||
setFace(true); // happy face
|
||||
}
|
||||
// if there are no objects in the way, keep moving
|
||||
Robot.motorsWrite(255, 255);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// return the distance in cm
|
||||
float getDistance() {
|
||||
// read the value from the sensor
|
||||
int sensorValue = Robot.analogRead(sensorPin);
|
||||
//Convert the sensor input to cm.
|
||||
float distance_cm = sensorValue * 1.27;
|
||||
return distance_cm;
|
||||
}
|
||||
|
||||
// make a happy or sad face
|
||||
void setFace(boolean onOff) {
|
||||
if (onOff) {
|
||||
// if true show a happy face
|
||||
Robot.background(0, 0, 255);
|
||||
Robot.setCursor(44, 60);
|
||||
Robot.stroke(0, 255, 0);
|
||||
Robot.setTextSize(4);
|
||||
Robot.print(":)");
|
||||
} else {
|
||||
// if false show an upset face
|
||||
Robot.background(255, 0, 0);
|
||||
Robot.setCursor(44, 60);
|
||||
Robot.stroke(0, 255, 0);
|
||||
Robot.setTextSize(4);
|
||||
Robot.print("X(");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/* 08 Remote Control
|
||||
|
||||
If you connect a IR receiver to the robot,
|
||||
you can control it like a RC car.
|
||||
Using the remote control comes with sensor
|
||||
pack, You can make the robot move around
|
||||
without even touching it!
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
* Connect the IRreceiver to D2
|
||||
* Remote control from Robot sensor pack
|
||||
|
||||
based on the IRremote library
|
||||
by Ken Shirriff
|
||||
http://arcfn.com
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
// include the necessary libraries
|
||||
#include <RobotIRremote.h>
|
||||
#include <RobotIRremoteTools.h>
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// Define a few commands from your remote control
|
||||
#define IR_CODE_FORWARD 284154405
|
||||
#define IR_CODE_BACKWARDS 284113605
|
||||
#define IR_CODE_TURN_LEFT 284129925
|
||||
#define IR_CODE_TURN_RIGHT 284127885
|
||||
#define IR_CODE_CONTINUE -1
|
||||
|
||||
boolean isActing = false; //If the robot is executing command from remote
|
||||
long timer;
|
||||
const long TIME_OUT = 150;
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Serial.begin(9600);
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
|
||||
// print some text to the screen
|
||||
beginIRremote(); // Start the receiver
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there is an IR command, process it
|
||||
if (IRrecived()) {
|
||||
processResult();
|
||||
resumeIRremote(); // resume receiver
|
||||
}
|
||||
|
||||
//If the robot does not receive any command, stop it
|
||||
if (isActing && (millis() - timer >= TIME_OUT)) {
|
||||
Robot.motorsStop();
|
||||
isActing = false;
|
||||
}
|
||||
}
|
||||
void processResult() {
|
||||
unsigned long res = getIRresult();
|
||||
switch (res) {
|
||||
case IR_CODE_FORWARD:
|
||||
changeAction(1, 1); //Move the robot forward
|
||||
break;
|
||||
case IR_CODE_BACKWARDS:
|
||||
changeAction(-1, -1); //Move the robot backwards
|
||||
break;
|
||||
case IR_CODE_TURN_LEFT:
|
||||
changeAction(-0.5, 0.5); //Turn the robot left
|
||||
break;
|
||||
case IR_CODE_TURN_RIGHT:
|
||||
changeAction(0.5, -0.5); //Turn the robot Right
|
||||
break;
|
||||
case IR_CODE_CONTINUE:
|
||||
timer = millis(); //Continue the last action, reset timer
|
||||
break;
|
||||
}
|
||||
}
|
||||
void changeAction(float directionLeft, float directionRight) {
|
||||
Robot.motorsWrite(255 * directionLeft, 255 * directionRight);
|
||||
timer = millis();
|
||||
isActing = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/* Picture Browser
|
||||
|
||||
You can make your own gallery/picture show with the
|
||||
Robot. Put some pictures on the SD card, start the
|
||||
sketch, they will diplay on the screen.
|
||||
|
||||
Use the left/right buttons to navigate through the
|
||||
previous and next images.
|
||||
|
||||
Press up or down to enter a mode where you change
|
||||
the pictures by rotating the robot.
|
||||
|
||||
You can add your own pictures onto the SD card, and
|
||||
view them in the Robot's gallery!
|
||||
|
||||
Pictures must be uncompressed BMP, 24-bit color depth,
|
||||
160 pixels wide, and 128 pixels tall.
|
||||
|
||||
They should be named as "picN.bmp". Replace 'N' with a
|
||||
number between 0 and 9.
|
||||
|
||||
The current code only supports 10 pictures. How would you
|
||||
improve it to handle more?
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h> // include the robot library
|
||||
#include <Wire.h>
|
||||
|
||||
const int NUM_PICS = 4; //Total number of pictures in Gallery
|
||||
|
||||
// name the modes
|
||||
const int CONTROL_MODE_KEY = 0;
|
||||
const int CONTROL_MODE_COMPASS = 1;
|
||||
|
||||
char buffer[] = "pic1.bmp"; // current file name
|
||||
int i = 1; // Current gallery sequence counter
|
||||
int mode = 0; // Current mode
|
||||
|
||||
// text to display on screen
|
||||
char modeNames[][9] = { "keyboard", "tilt " };
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Robot.beginSD();
|
||||
Robot.beginTFT();
|
||||
Robot.begin();
|
||||
|
||||
// draw "lg0.bmp" and "lg1.bmp" on the screen
|
||||
Robot.displayLogos();
|
||||
|
||||
// draw init3.bmp from the SD card on the screen
|
||||
Robot.drawBMP("init3.bmp", 0, 0);
|
||||
|
||||
// display instructions
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("The gallery\n\n has 2 modes, in\n keyboard mode, L/R\n key for switching\n pictures, U/D key\n for changing modes", 5, 5);
|
||||
delay(6000);
|
||||
Robot.clearScreen();
|
||||
Robot.drawBMP("pb.bmp", 0, 0);
|
||||
Robot.text("In tilt mode,\n quickly tilt the\n robot to switch\n pictures", 5, 5);
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
buffer[3] = '0' + i; // change filename of the img to be displayed
|
||||
Robot.drawBMP(buffer, 0, 0); // draw the file on the screen
|
||||
// change control modes
|
||||
switch (mode) {
|
||||
case CONTROL_MODE_COMPASS:
|
||||
compassControl(3);
|
||||
break;
|
||||
case CONTROL_MODE_KEY:
|
||||
keyboardControl();
|
||||
break;
|
||||
}
|
||||
delay(200);
|
||||
}
|
||||
|
||||
void keyboardControl() {
|
||||
//Use buttons to control the gallery
|
||||
while (true) {
|
||||
int keyPressed = Robot.keyboardRead(); // read the button values
|
||||
switch (keyPressed) {
|
||||
case BUTTON_LEFT: // display previous picture
|
||||
if (--i < 1) {
|
||||
i = NUM_PICS;
|
||||
}
|
||||
return;
|
||||
case BUTTON_MIDDLE: // do nothing
|
||||
case BUTTON_RIGHT: // display next picture
|
||||
if (++i > NUM_PICS) {
|
||||
i = 1;
|
||||
}
|
||||
return;
|
||||
case BUTTON_UP: // change mode
|
||||
changeMode(-1);
|
||||
return;
|
||||
case BUTTON_DOWN: // change mode
|
||||
changeMode(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if controlling by the compass
|
||||
void compassControl(int change) {
|
||||
// Rotate the robot to change the pictures
|
||||
while (true) {
|
||||
// read the value of the compass
|
||||
int oldV = Robot.compassRead();
|
||||
|
||||
//get the change of angle
|
||||
int diff = Robot.compassRead() - oldV;
|
||||
if (diff > 180) {
|
||||
diff -= 360;
|
||||
} else if (diff < -180) {
|
||||
diff += 360;
|
||||
}
|
||||
|
||||
if (abs(diff) > change) {
|
||||
if (++i > NUM_PICS) {
|
||||
i = 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// chage modes, if buttons are pressed
|
||||
int keyPressed = Robot.keyboardRead();
|
||||
switch (keyPressed) {
|
||||
case BUTTON_UP:
|
||||
changeMode(-1);
|
||||
return;
|
||||
case BUTTON_DOWN:
|
||||
changeMode(1);
|
||||
return;
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
// Change the control mode and display it on the LCD
|
||||
void changeMode(int changeDir) {
|
||||
// alternate modes
|
||||
mode += changeDir;
|
||||
if (mode < 0) {
|
||||
mode = 1;
|
||||
} else if (mode > 1) {
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
// display the mode on screen
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.rect(0, 0, 128, 12);
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Control:", 2, 2);
|
||||
Robot.text(modeNames[mode], 52, 2);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* Robot Rescue
|
||||
|
||||
In this example, the robot enters the line following mode and
|
||||
plays some music until it reaches its target. Once it finds the
|
||||
target, it pushes it out of the track. It then returns to the
|
||||
track and looks for a second target.
|
||||
|
||||
You can make the robot push as many objects as you want to, just
|
||||
add more to calls to the rescue function or even move that code
|
||||
into the loop.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
* some objects for the robot to push
|
||||
* a line-following circuit
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h> // include the robot library
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
Robot.beginSpeaker();
|
||||
|
||||
// draw "lg0.bmp" and "lg1.bmp" on the screen
|
||||
Robot.displayLogos();
|
||||
|
||||
// display the line following instructional image from the SD card
|
||||
Robot.drawBMP("lf.bmp", 0, 0);
|
||||
|
||||
// play the chase music file
|
||||
Robot.playFile("chase.sqm");
|
||||
|
||||
// add the instructions
|
||||
Robot.text("Rescue\n\n place the robot on\n the rescue track\n pushing the\n obstacles away", 5, 5);
|
||||
Robot.text("Press the middle\n button to start...", 5, 61);
|
||||
Robot.waitContinue();
|
||||
|
||||
// start
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.rect(0, 0, 128, 80); // erase the previous text
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Start", 5, 5);
|
||||
|
||||
// use this to calibrate the line following algorithm
|
||||
// uncomment one or the other to see the different behaviors of the robot
|
||||
// Robot.lineFollowConfig(14, 9, 50, 10);
|
||||
Robot.lineFollowConfig(11, 7, 60, 5);
|
||||
|
||||
// run the rescue sequence
|
||||
rescueSequence();
|
||||
// find the track again
|
||||
goToNext();
|
||||
// run the rescue sequence a second time
|
||||
rescueSequence();
|
||||
|
||||
// here you could go on ...
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//nothing here, the program only runs once.
|
||||
}
|
||||
|
||||
// run the sequence
|
||||
void rescueSequence() {
|
||||
//set the motor board into line-follow mode
|
||||
Robot.setMode(MODE_LINE_FOLLOW);
|
||||
|
||||
while (!Robot.isActionDone()) { // wait until it is no longer following the line
|
||||
}
|
||||
delay(1000);
|
||||
|
||||
// do the rescue operation
|
||||
doRescue();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void doRescue() {
|
||||
// Reached the endline, engage the target
|
||||
Robot.motorsWrite(200, 200);
|
||||
delay(250);
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
|
||||
// Turn the robot
|
||||
Robot.turn(90);
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
|
||||
// Move forward
|
||||
Robot.motorsWrite(200, 200);
|
||||
delay(500);
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
|
||||
// move backwards, leave the target
|
||||
Robot.motorsWrite(-200, -200);
|
||||
delay(500);
|
||||
Robot.motorsStop();
|
||||
}
|
||||
|
||||
void goToNext() {
|
||||
// Turn the robot
|
||||
Robot.turn(-90);
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/* Hello User
|
||||
|
||||
Hello User! This sketch is the first thing you see
|
||||
when starting this robot. It gives you a warm welcome,
|
||||
showing you some of the really amazing abilities of
|
||||
the robot, and make itself really personal to you.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h> // include the robot library
|
||||
#include <Wire.h>
|
||||
|
||||
// include the utility function for ths sketch
|
||||
// see the details below
|
||||
#include <utility/RobotTextManager.h>
|
||||
|
||||
char buffer[20];//for storing user name
|
||||
|
||||
void setup() {
|
||||
//necessary initialization sequence
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
|
||||
// show the logos from the SD card
|
||||
Robot.displayLogos();
|
||||
|
||||
// clear the screen
|
||||
Robot.clearScreen();
|
||||
|
||||
// From now on, display different slides of
|
||||
// text/pictures in sequence. The so-called
|
||||
// scripts are strings of text stored in the
|
||||
// robot's memory
|
||||
|
||||
// these functions are explained below
|
||||
|
||||
//Script 6
|
||||
textManager.writeScript(5, 4, 0);
|
||||
textManager.writeScript(9, 10, 0);
|
||||
Robot.waitContinue();
|
||||
delay(500);
|
||||
Robot.clearScreen();
|
||||
|
||||
//Script 7
|
||||
textManager.writeScript(6, 4, 0);
|
||||
textManager.writeScript(9, 10, 0);
|
||||
Robot.waitContinue();
|
||||
delay(500);
|
||||
Robot.clearScreen();
|
||||
|
||||
//Script 8
|
||||
// this function enables sound and images at once
|
||||
textManager.showPicture("init2.bmp", 0, 0);
|
||||
|
||||
textManager.writeScript(7, 2, 0);
|
||||
textManager.writeScript(9, 7, 0);
|
||||
Robot.waitContinue();
|
||||
delay(500);
|
||||
Robot.clearScreen();
|
||||
|
||||
//Script 9
|
||||
textManager.showPicture("init3.bmp", 0, 0);
|
||||
textManager.writeScript(8, 2, 0);
|
||||
textManager.writeScript(9, 7, 0);
|
||||
Robot.waitContinue();
|
||||
delay(500);
|
||||
Robot.clearScreen();
|
||||
|
||||
//Script 11
|
||||
textManager.writeScript(10, 4, 0);
|
||||
textManager.writeScript(9, 10, 0);
|
||||
Robot.waitContinue();
|
||||
delay(500);
|
||||
Robot.clearScreen();
|
||||
|
||||
//Input screen
|
||||
textManager.writeScript(0, 1, 1);
|
||||
textManager.input(3, 1, USERNAME);
|
||||
|
||||
textManager.writeScript(1, 5, 1);
|
||||
textManager.input(7, 1, ROBOTNAME);
|
||||
|
||||
delay(1000);
|
||||
Robot.clearScreen();
|
||||
|
||||
//last screen
|
||||
textManager.showPicture("init4.bmp", 0, 0);
|
||||
textManager.writeText(1, 2, "Hello");
|
||||
Robot.userNameRead(buffer);
|
||||
textManager.writeText(3, 2, buffer);
|
||||
|
||||
textManager.writeScript(4, 10, 0);
|
||||
|
||||
Robot.waitContinue(BUTTON_LEFT);
|
||||
Robot.waitContinue(BUTTON_RIGHT);
|
||||
textManager.showPicture("kt1.bmp", 0, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// do nothing here
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
textManager mostly contains helper functions for
|
||||
R06_Wheel_Calibration and R01_Hello_User.
|
||||
|
||||
The ones used in this example:
|
||||
textManager.setMargin(margin_left, margin_top):
|
||||
Configure the left and top margin for text
|
||||
display. The margins will be used for
|
||||
textManager.writeText().
|
||||
Parameters:
|
||||
margin_left, margin_top: the margin values
|
||||
from the top and left side of the screen.
|
||||
Returns:
|
||||
none
|
||||
|
||||
textManager.writeScript(script_number,line,column):
|
||||
Display a script of Hello User example.
|
||||
Parameters:
|
||||
script_number: an int value representing the
|
||||
script to be displayed.
|
||||
line, column: in which line,column is the script
|
||||
displayed. Same as writeText().
|
||||
Returns:
|
||||
none
|
||||
|
||||
textManager.input(line,column,codename):
|
||||
Print an input indicator(">") in the line and column,
|
||||
dispaly and receive input from a virtual keyboard,
|
||||
and save the value into EEPROM represented by codename
|
||||
Parameters:
|
||||
line,column: int values represents where the input
|
||||
starts. Same as wirteText().
|
||||
codename: either USERNAME,ROBOTNAME,CITYNAME or
|
||||
COUNTRYNAME. You can call Robot.userNameRead(),
|
||||
robotNameRead(),cityNameRead() or countryNameRead()
|
||||
to access the values later.
|
||||
Returns:
|
||||
none;
|
||||
|
||||
textManager.writeText(line,column,text):
|
||||
Display text on the specific line and column.
|
||||
It's different from Robot.text() as the later
|
||||
uses pixels for positioning the text.
|
||||
Parameters:
|
||||
line:in which line is the text displayed. Each line
|
||||
is 10px high.
|
||||
column:in which column is the text displayed. Each
|
||||
column is 8px wide.
|
||||
text:a char array(string) of the text to be displayed.
|
||||
Returns:
|
||||
none
|
||||
|
||||
textManager.showPicture(filename, x, y):
|
||||
It has the same functionality as Robot.drawPicture(),
|
||||
while fixing the conflict between drawPicture() and
|
||||
sound playing. Using Robot.drawPicture(), it'll have
|
||||
glitches when playing sound at the same time. Using
|
||||
showPicture(), it'll stop sound when displaying
|
||||
picture, so preventing the problem.
|
||||
Parameters:
|
||||
filename:string, name of the bmp file in sd
|
||||
x,y: int values, position of the picture
|
||||
Returns:
|
||||
none
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
All IO Ports
|
||||
|
||||
This example goes through all the IO ports on your robot and
|
||||
reads/writes from/to them. Uncomment the different lines inside
|
||||
the loop to test the different possibilities.
|
||||
|
||||
The M inputs on the Control Board are multiplexed and therefore
|
||||
it is not recommended to use them as outputs. The D pins on the
|
||||
Control Board as well as the D pins on the Motor Board go directly
|
||||
to the microcontroller and therefore can be used both as inputs
|
||||
and outputs.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// use arrays to store the names of the pins to be read
|
||||
uint8_t arr[] = { M0, M1, M2, M3, M4, M5, M6, M7 };
|
||||
uint8_t arr2[] = { D0, D1, D2, D3, D4, D5 };
|
||||
uint8_t arr3[] = { D7, D8, D9, D10 };
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// open the serial port to send the information of what you are reading
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read all the D inputs at the Motor Board as analog
|
||||
//analogReadB_Ds();
|
||||
|
||||
// read all the D inputs at the Motor Board as digital
|
||||
//digitalReadB_Ds();
|
||||
|
||||
// read all the M inputs at the Control Board as analog
|
||||
//analogReadMs();
|
||||
|
||||
// read all the M inputs at the Control Board as digital
|
||||
//digitalReadMs();
|
||||
|
||||
// read all the D inputs at the Control Board as analog
|
||||
analogReadT_Ds();
|
||||
|
||||
// read all the D inputs at the Control Board as digital
|
||||
//digitalReadT_Ds();
|
||||
|
||||
// write all the D outputs at the Motor Board as digital
|
||||
//digitalWriteB_Ds();
|
||||
|
||||
// write all the D outputs at the Control Board as digital
|
||||
//digitalWriteT_Ds();
|
||||
delay(40);
|
||||
}
|
||||
|
||||
// read all M inputs on the Control Board as analog inputs
|
||||
void analogReadMs() {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Serial.print(Robot.analogRead(arr[i]));
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
// read all M inputs on the Control Board as digital inputs
|
||||
void digitalReadMs() {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Serial.print(Robot.digitalRead(arr[i]));
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
// read all D inputs on the Control Board as analog inputs
|
||||
void analogReadT_Ds() {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Serial.print(Robot.analogRead(arr2[i]));
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
// read all D inputs on the Control Board as digital inputs
|
||||
void digitalReadT_Ds() {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Serial.print(Robot.digitalRead(arr2[i]));
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
// write all D outputs on the Control Board as digital outputs
|
||||
void digitalWriteT_Ds() {
|
||||
// turn all the pins on
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Robot.digitalWrite(arr2[i], HIGH);
|
||||
}
|
||||
delay(500);
|
||||
|
||||
// turn all the pins off
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Robot.digitalWrite(arr2[i], LOW);
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// write all D outputs on the Motor Board as digital outputs
|
||||
void digitalWriteB_Ds() {
|
||||
// turn all the pins on
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Robot.digitalWrite(arr3[i], HIGH);
|
||||
}
|
||||
delay(500);
|
||||
|
||||
// turn all the pins off
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Robot.digitalWrite(arr3[i], LOW);
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// read all D inputs on the Motor Board as analog inputs
|
||||
void analogReadB_Ds() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Serial.print(Robot.analogRead(arr3[i]));
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
// read all D inputs on the Motor Board as digital inputs
|
||||
void digitalReadB_Ds() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Serial.print(Robot.digitalRead(arr3[i]));
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
40
arduino/libraries/Robot_Control/examples/learn/Beep/Beep.ino
Normal file
40
arduino/libraries/Robot_Control/examples/learn/Beep/Beep.ino
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Beep
|
||||
|
||||
Test different pre-configured beeps on
|
||||
the robot's speaker.
|
||||
|
||||
Possible beeps are:
|
||||
- BEEP_SIMPLE
|
||||
- BEEP_DOUBLE
|
||||
- BEEP_LONG
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the sound speaker
|
||||
Robot.beginSpeaker();
|
||||
}
|
||||
void loop() {
|
||||
Robot.beep(BEEP_SIMPLE);
|
||||
delay(1000);
|
||||
Robot.beep(BEEP_DOUBLE);
|
||||
delay(1000);
|
||||
Robot.beep(BEEP_LONG);
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Clean EEPROM
|
||||
|
||||
This example erases the user information stored on the
|
||||
external EEPROM memory chip on your robot.
|
||||
|
||||
BEWARE, this will erase the following information:
|
||||
- your name
|
||||
- your robots name given by you
|
||||
- your city and country if you configured them via software
|
||||
|
||||
EEPROMs shouldn't be rewritten too often, therefore the
|
||||
code runs only during setup and not inside loop.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// write empty strings for the different fields
|
||||
Robot.userNameWrite("");
|
||||
Robot.robotNameWrite("");
|
||||
Robot.cityNameWrite("");
|
||||
Robot.countryNameWrite("");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// do nothing
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Compass
|
||||
|
||||
Try the compass both on the robot's TFT
|
||||
and through the serial port.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the robot's screen
|
||||
Robot.beginTFT();
|
||||
|
||||
// initialize the serial port
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the compass
|
||||
int compass = Robot.compassRead();
|
||||
|
||||
// print out the sensor's value
|
||||
Serial.println(compass);
|
||||
|
||||
// show the value on the robot's screen
|
||||
Robot.drawCompass(compass);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
IR array
|
||||
|
||||
Read the analog value of the IR sensors at the
|
||||
bottom of the robot. The also-called line following
|
||||
sensors are a series of pairs of IR sender/receiver
|
||||
used to detect how dark it is underneath the robot.
|
||||
|
||||
The information coming from the sensor array is stored
|
||||
into the Robot.IRarray[] and updated using the Robot.updateIR()
|
||||
method.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the serial port
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// store the sensor information into the array
|
||||
Robot.updateIR();
|
||||
|
||||
// iterate the array and print the data to the Serial port
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Serial.print(Robot.IRarray[i]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
LCD Debug Print
|
||||
|
||||
Use the Robot's library function debugPrint() to
|
||||
quickly send a sensor reading to the robot's creen.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
int value;
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the screen
|
||||
Robot.beginTFT();
|
||||
}
|
||||
void loop() {
|
||||
// read a value
|
||||
value = analogRead(A4);
|
||||
|
||||
// send the value to the screen
|
||||
Robot.debugPrint(value);
|
||||
|
||||
delay(40);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
LCD Print
|
||||
|
||||
Print the reading from a sensor to the screen.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
int value;
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the robot's screen
|
||||
Robot.beginTFT();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read a analog port
|
||||
value = Robot.analogRead(TK4);
|
||||
|
||||
// write the sensor value on the screen
|
||||
Robot.stroke(0, 255, 0);
|
||||
Robot.textSize(1);
|
||||
Robot.text(value, 0, 0);
|
||||
|
||||
delay(500);
|
||||
|
||||
// erase the previous text on the screen
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.textSize(1);
|
||||
Robot.text(value, 0, 0);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
LCD Write Text
|
||||
|
||||
Use the Robot's library function text() to
|
||||
print out text to the robot's screen. Take
|
||||
into account that you need to erase the
|
||||
information before continuing writing.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the screen
|
||||
Robot.beginTFT();
|
||||
}
|
||||
void loop() {
|
||||
Robot.stroke(0, 0, 0); // choose the color black
|
||||
Robot.text("Hello World", 0, 0); // print the text
|
||||
delay(2000);
|
||||
Robot.stroke(255, 255, 255); // choose the color white
|
||||
Robot.text("Hello World", 0, 0); // writing text in the same color as the BG erases the text!
|
||||
|
||||
Robot.stroke(0, 0, 0); // choose the color black
|
||||
Robot.text("I am a robot", 0, 0); // print the text
|
||||
delay(3000);
|
||||
Robot.stroke(255, 255, 255); // choose the color black
|
||||
Robot.text("I am a robot", 0, 0); // print the text
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Line Following with Pause
|
||||
|
||||
As the robot has two processors, one to command the motors and one to
|
||||
take care of the screen and user input, it is possible to write
|
||||
programs that put one part of the robot to do something and get the
|
||||
other half to control it.
|
||||
|
||||
This example shows how the Control Board assigns the Motor one to
|
||||
follow a line, but asks it to stop every 3 seconds.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the screen
|
||||
Robot.beginTFT();
|
||||
|
||||
// get some time to place the robot on the ground
|
||||
delay(3000);
|
||||
|
||||
// set the robot in line following mode
|
||||
Robot.setMode(MODE_LINE_FOLLOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// tell the robot to take a break and stop
|
||||
Robot.pauseMode(true);
|
||||
Robot.debugPrint('p');
|
||||
delay(3000);
|
||||
|
||||
// tell the robot to move on
|
||||
Robot.pauseMode(false);
|
||||
Robot.debugPrint('>');
|
||||
delay(3000);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Melody
|
||||
|
||||
Plays a melody stored in a string.
|
||||
|
||||
The notes and durations are encoded as follows:
|
||||
|
||||
NOTES:
|
||||
c play "C"
|
||||
C play "#C"
|
||||
d play "D"
|
||||
D play "#D"
|
||||
e play "E"
|
||||
f play "F"
|
||||
F play "#F"
|
||||
g play "G"
|
||||
G play "#G"
|
||||
a play "A"
|
||||
A play "#A"
|
||||
b play "B"
|
||||
- silence
|
||||
|
||||
DURATIONS:
|
||||
1 Set as full note
|
||||
2 Set as half note
|
||||
4 Set as quarter note
|
||||
8 Set as eigth note
|
||||
|
||||
SPECIAL NOTATION:
|
||||
. Make the previous note 3/4 the length
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
|
||||
This code uses the Squawk sound library designed by STG. For
|
||||
more information about it check: http://github.com/stg/squawk
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the sound library
|
||||
Robot.beginSpeaker();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// array containing the melody
|
||||
char aTinyMelody[] = "8eF-FFga4b.a.g.F.8beee-d2e.1-";
|
||||
|
||||
// play the melody
|
||||
Robot.playMelody(aTinyMelody);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Motor Test
|
||||
|
||||
Just see if the robot can move and turn.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Robot.motorsWrite(255, 255); // move forward
|
||||
delay(2000);
|
||||
Robot.motorsStop(); // fast stop
|
||||
delay(1000);
|
||||
Robot.motorsWrite(-255, -255); // backward
|
||||
delay(1000);
|
||||
Robot.motorsWrite(0, 0); // slow stop
|
||||
delay(1000);
|
||||
Robot.motorsWrite(-255, 255); // turn left
|
||||
delay(2000);
|
||||
Robot.motorsStop(); // fast stop
|
||||
delay(1000);
|
||||
Robot.motorsWrite(255, -255); // turn right
|
||||
delay(2000);
|
||||
Robot.motorsStop(); // fast stop
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Speed by Potentiometer
|
||||
|
||||
Control the robot's speed using the on-board
|
||||
potentiometer. The speed will be printed on
|
||||
the TFT screen.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
|
||||
// initialize the screen
|
||||
Robot.beginTFT();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value of the potentiometer
|
||||
int val = map(Robot.knobRead(), 0, 1023, -255, 255);
|
||||
|
||||
// print the value to the TFT screen
|
||||
Robot.debugPrint(val);
|
||||
|
||||
// set the same speed on both of the robot's wheels
|
||||
Robot.motorsWrite(val, val);
|
||||
delay(10);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Turn Test
|
||||
|
||||
Check if the robot turns a certain amount of degrees.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the robot
|
||||
Robot.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Robot.turn(50); //turn 50 degrees to the right
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
|
||||
Robot.turn(-100); //turn 100 degrees to the left
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Keyboard Test
|
||||
|
||||
Check how the robot's keyboard works. This example
|
||||
sends the data about the key pressed through the
|
||||
serial port.
|
||||
|
||||
All the buttons on the Control Board are tied up to a
|
||||
single analog input pin, in this way it is possible to multiplex a
|
||||
whole series of buttons on one single pin.
|
||||
|
||||
It is possible to recalibrate the thresholds of the buttons using
|
||||
the Robot.keyboardCalibrate() function, that takes a 5 ints long
|
||||
array as parameter
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
#include <ArduinoRobot.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the serial port
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// print out the keyboard readings
|
||||
Serial.println(Robot.keyboardRead());
|
||||
delay(100);
|
||||
}
|
||||
Reference in New Issue
Block a user