1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@ -1,24 +1,24 @@
/* 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
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
*/
@ -27,7 +27,7 @@
int commands[20]; // array for storing commands
void setup() {
// initialize the Robot, SD card, and display
// initialize the Robot, SD card, and display
Robot.begin();
Robot.beginTFT();
Robot.beginSD();
@ -37,39 +37,39 @@ void setup() {
}
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.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;
for (int i = 0; i < 20; i++)
commands[i] = -1;
}
// add commands to the array
void addCommands() {
Robot.stroke(0,0,0);
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
for (int i = 0; i < 20;) { //max 20 commands
int key = Robot.keyboardRead();
if(key == BUTTON_MIDDLE) { //finish input
if (key == BUTTON_MIDDLE) { //finish input
break;
}else if(key == BUTTON_NONE) { //if no button is pressed
} else if (key == BUTTON_NONE) { //if no button is pressed
continue;
}
commands[i] = key; // save the button to the array
@ -82,11 +82,11 @@ void addCommands() {
// run through the array and move the robot
void executeCommands() {
// print status to the screen
Robot.text("Excuting...",5,70);
Robot.text("Excuting...", 5, 70);
// read through the array and move accordingly
for(int i=0; i<20; i++) {
switch(commands[i]) {
for (int i = 0; i < 20; i++) {
switch (commands[i]) {
case BUTTON_LEFT:
Robot.turn(-90);
break;
@ -103,10 +103,10 @@ void executeCommands() {
return;
}
// print the current command to the screen
Robot.stroke(255,0,0);
Robot.stroke(255, 0, 0);
PrintCommandI(i, 86);
delay(1000);
// stop moving for a second
Robot.motorsStop();
delay(1000);
@ -115,7 +115,7 @@ void executeCommands() {
// convert the button press to a single character
char keyToChar(int key) {
switch(key) {
switch (key) {
case BUTTON_LEFT:
return '<';
case BUTTON_RIGHT:
@ -129,6 +129,6 @@ char keyToChar(int key) {
// display a command
void PrintCommandI(int i, int originY) {
Robot.text(keyToChar(commands[i]), i%14*8+5, i/14*10+originY);
Robot.text(keyToChar(commands[i]), i % 14 * 8 + 5, i / 14 * 10 + originY);
}

View File

@ -1,19 +1,19 @@
/* Robot Line Follow
This sketch demonstrates the line following capabilities
of the Arduino Robot. On the floor, place some black
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
*/
@ -22,7 +22,7 @@
long timerOrigin; // used for counting elapsed time
void setup() {
// initialize the Robot, SD card, display, and speaker
// initialize the Robot, SD card, display, and speaker
Robot.begin();
Robot.beginTFT();
Robot.beginSD();
@ -30,45 +30,45 @@ void setup() {
// 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
// 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);
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
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.stroke(0, 0, 0);
Robot.text("Done!", 5, 45);
}
void loop() {
//nothing here, the program only runs once. Reset the robot
//nothing here, the program only runs once. Reset the robot
//to do it again!
}

View File

@ -1,18 +1,18 @@
/* 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
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
*/
@ -25,12 +25,12 @@
F: go forward
B: go backwards
The number after each command determines how long
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";
char danceScript[] = "S4L1R1S2F1B1S1\0";
int currentScript = 0; // what step are we at
@ -49,34 +49,34 @@ long waitFrom;
long waitTime = 0;
void setup() {
// initialize the Robot, SD card, display, and speaker
// 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) {
switch (key) {
case BUTTON_UP:
case BUTTON_LEFT:
play(-1); //play previous song
@ -86,25 +86,25 @@ void loop() {
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]);
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
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)
if (millis() - waitFrom >= waitTime)
return false;
else
return true;
@ -122,9 +122,9 @@ void resetWait() {
}
// read the direction and dirstion of the steps
void parseCommand(char dir, char duration) {
void parseCommand(char dir, char duration) {
//convert the scripts to action
switch(dir) {
switch (dir) {
case 'L':
Robot.motorsWrite(-255, 255);
break;
@ -142,7 +142,7 @@ void parseCommand(char dir, char duration) {
break;
}
//You can change "500" to change the pace of dancing
wait(500*(duration-'0'));
wait(500 * (duration - '0'));
}
// display the song
@ -154,10 +154,10 @@ void setInterface() {
// display the next song
void select(int seq, boolean onOff) {
if(onOff){//select
if (onOff) { //select
Robot.stroke(0, 0, 0);
Robot.text(musics[seq], 0, 0);
}else{//deselect
} else { //deselect
Robot.stroke(255, 255, 255);
Robot.text(musics[seq], 0, 0);
}
@ -166,9 +166,9 @@ void select(int seq, boolean onOff) {
// 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?
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

View File

@ -1,21 +1,21 @@
/* 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.
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
*/
@ -35,32 +35,32 @@ void setup() {
Robot.displayLogos();
}
void loop() {
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;
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;
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
// change the speed of the left wheel
speedLeft = 255;
speedRight = 255+diff;
speedRight = 255 + diff;
}
// write out to the motors
Robot.motorsWrite(speedLeft, speedRight);

View File

@ -1,21 +1,21 @@
/* Robot Inputs
This sketch shows you how to use the on-board
potentiometer and buttons as 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.
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
*/
@ -26,16 +26,16 @@ int tempo = 60;
int pitch = 1000;
void setup() {
// initialize the Robot, SD card, speaker, and display
// 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
// draw "lg0.bmp" and "lg1.bmp" on the screen
Robot.displayLogos();
// play a sound file
// play a sound file
Robot.playFile("Melody.sqm");
}
@ -50,55 +50,55 @@ void loop() {
// Draw the basic interface
void renderUI() {
//fill the buttons blank
Robot.fill(255, 255, 255);
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
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.fill(255, 190, 0);
Robot.rect(53, 110, fullPart, 13);
Robot.fill(255, 255, 255);
Robot.rect(53+fullPart, 110, 58-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) {
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);
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);
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;
if (pitch > 2000) pitch = 2000;
Robot.fill(0, 0, 255);
Robot.rect(73, 38, 13, 13);
@ -106,8 +106,8 @@ void keyDown(int keyCode) {
case BUTTON_DOWN:
//down button pressed, reduces pitch
pitch -= 120;
if(pitch < 200){
pitch = 200;
if (pitch < 200) {
pitch = 200;
}
Robot.fill(0, 0, 255);
@ -117,49 +117,49 @@ void keyDown(int keyCode) {
//middle button pressed, resets tempo and pitch
tempo = 60;
pitch = 1000;
Robot.fill(160,160,160);
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
//encountered the first time), the interface will be
//re-drawn.
if(oldKey != BUTTON_NONE){
if (oldKey != BUTTON_NONE) {
renderUI();
}
break;
}
if(oldKey != keyCode) {
if (oldKey != keyCode) {
// change the song's tempo
Robot.tempoWrite(tempo);
// change the song's pitch
Robot.tuneWrite(float(pitch/1000.0));
Robot.tuneWrite(float(pitch / 1000.0));
}
oldKey = keyCode;
}
//Draw a circle according to value
//of the knob.
//of the knob.
void drawKnob(int val) {
static int val_old;
int r=map(val,0,1023,1,15);
//Only updates when the
int r = map(val, 0, 1023, 1, 15);
//Only updates when the
//value changes.
if(val_old!=r){
if (val_old != r) {
Robot.noFill();
//erase the old circle
Robot.stroke(255, 255, 255);
Robot.circle(26,116,r+1);
Robot.circle(26, 116, r + 1);
//draw the new circle
Robot.stroke(255, 0, 255);
Robot.circle(26,116,r);
Robot.circle(26, 116, r);
Robot.stroke(0, 0, 0);
val_old=r;
val_old = r;
}
}

View File

@ -1,11 +1,11 @@
/* 6 Wheel Calibration
*
* Use this sketch to calibrate the wheels in your robot.
* Your robot should drive as straight as possible when
* 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
* 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
@ -14,7 +14,7 @@
#include <ArduinoRobot.h>
void setup(){
void setup() {
Serial.begin(9600);
Robot.begin();
Robot.beginTFT();
@ -22,17 +22,17 @@ void setup(){
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);
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);
}

View File

@ -1,20 +1,20 @@
/* Runaway Robot
Play tag with your robot! With an ultrasonic
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
*/
@ -30,14 +30,14 @@ void setup() {
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
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
@ -45,7 +45,7 @@ void loop() {
setFace(true); // happy face
}
// if there are no objects in the way, keep moving
Robot.motorsWrite(255, 255);
Robot.motorsWrite(255, 255);
delay(100);
}
@ -54,20 +54,20 @@ 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;
float distance_cm = sensorValue * 1.27;
return distance_cm;
}
// make a happy or sad face
void setFace(boolean onOff) {
if(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{
} else {
// if false show an upset face
Robot.background(255, 0, 0);
Robot.setCursor(44, 60);

View File

@ -1,12 +1,12 @@
/* 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
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:
Circuit:
* Arduino Robot
* Connect the IRreceiver to D2
* Remote control from Robot sensor pack
@ -14,12 +14,12 @@
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
*/
@ -35,12 +35,12 @@
#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;
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
// initialize the Robot, SD card, display, and speaker
Serial.begin(9600);
Robot.begin();
Robot.beginTFT();
@ -56,36 +56,36 @@ void loop() {
processResult();
resumeIRremote(); // resume receiver
}
//If the robot does not receive any command, stop it
if(isActing && (millis()-timer>=TIME_OUT)){
if (isActing && (millis() - timer >= TIME_OUT)) {
Robot.motorsStop();
isActing=false;
isActing = false;
}
}
void processResult() {
unsigned long res = getIRresult();
switch(res){
switch (res) {
case IR_CODE_FORWARD:
changeAction(1,1); //Move the robot forward
changeAction(1, 1); //Move the robot forward
break;
case IR_CODE_BACKWARDS:
changeAction(-1,-1); //Move the robot backwards
changeAction(-1, -1); //Move the robot backwards
break;
case IR_CODE_TURN_LEFT:
changeAction(-0.5,0.5); //Turn the robot 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
changeAction(0.5, -0.5); //Turn the robot Right
break;
case IR_CODE_CONTINUE:
timer=millis(); //Continue the last action, reset timer
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;
void changeAction(float directionLeft, float directionRight) {
Robot.motorsWrite(255 * directionLeft, 255 * directionRight);
timer = millis();
isActing = true;
}

View File

@ -1,25 +1,25 @@
/* 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
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
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,
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
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
The current code only supports 10 pictures. How would you
improve it to handle more?
Circuit:
@ -29,7 +29,7 @@
by X. Yang
modified 12 May 2013
by D. Cuartielles
This example is in the public domain
*/
@ -49,14 +49,14 @@ int mode = 0; // Current mode
char modeNames[][9] = { "keyboard", "tilt " };
void setup() {
// initialize the Robot, SD card, display, and speaker
// initialize the Robot, SD card, display, and speaker
Robot.beginSD();
Robot.beginTFT();
Robot.begin();
// draw "lg0.bmp" and "lg1.bmp" on the screen
// 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);
@ -71,10 +71,10 @@ void setup() {
}
void loop() {
buffer[3] = '0'+i;// change filename of the img to be displayed
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) {
switch (mode) {
case CONTROL_MODE_COMPASS:
compassControl(3);
break;
@ -87,15 +87,15 @@ void loop() {
void keyboardControl() {
//Use buttons to control the gallery
while(true) {
while (true) {
int keyPressed = Robot.keyboardRead(); // read the button values
switch(keyPressed) {
switch (keyPressed) {
case BUTTON_LEFT: // display previous picture
if(--i < 1) i = NUM_PICS;
if (--i < 1) i = NUM_PICS;
return;
case BUTTON_MIDDLE: // do nothing
case BUTTON_RIGHT: // display next picture
if(++i > NUM_PICS) i = 1;
if (++i > NUM_PICS) i = 1;
return;
case BUTTON_UP: // change mode
changeMode(-1);
@ -110,23 +110,23 @@ void keyboardControl() {
// if controlling by the compass
void compassControl(int change) {
// Rotate the robot to change the pictures
while(true) {
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;
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) {
switch (keyPressed) {
case BUTTON_UP:
changeMode(-1);
return;
@ -142,13 +142,13 @@ void compassControl(int change) {
void changeMode(int changeDir) {
// alternate modes
mode += changeDir;
if(mode < 0) {
if (mode < 0) {
mode = 1;
} else if(mode > 1)
mode=0;
// display the mode on screen
Robot.fill(255, 255, 255);
} 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);

View File

@ -1,8 +1,8 @@
/* 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
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
@ -18,20 +18,20 @@
by X. Yang
modified 12 May 2013
by D. Cuartielles
This example is in the public domain
*/
#include <ArduinoRobot.h> // include the robot library
void setup(){
// initialize the Robot, SD card, display, and speaker
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
// draw "lg0.bmp" and "lg1.bmp" on the screen
Robot.displayLogos();
// display the line following instructional image from the SD card
@ -51,13 +51,13 @@ void setup(){
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
// run the rescue sequence
rescueSequence();
Robot.text("Found obstacle", 5, 12);
// find the track again
@ -66,24 +66,24 @@ void setup(){
// run the rescue sequence a second time
rescueSequence();
Robot.text("Found obstacle", 5, 26);
// here you could go on ...
// write status on the screen
Robot.stroke(0, 0, 0);
Robot.text("Done!", 5, 25);
}
void loop(){
void loop() {
//nothing here, the program only runs once.
}
// run the sequence
void rescueSequence(){
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
Robot.setMode(MODE_LINE_FOLLOW);
while (!Robot.isActionDone()) { // wait until it is no longer following the line
}
delay(1000);
@ -92,32 +92,32 @@ void rescueSequence(){
delay(1000);
}
void doRescue(){
void doRescue() {
// Reached the endline, engage the target
Robot.motorsWrite(200,200);
Robot.motorsWrite(200, 200);
delay(250);
Robot.motorsStop();
delay(1000);
// Turn the robot
// Turn the robot
Robot.turn(90);
Robot.motorsStop();
delay(1000);
// Move forward
Robot.motorsWrite(200,200);
Robot.motorsWrite(200, 200);
delay(500);
Robot.motorsStop();
delay(1000);
// move backwards, leave the target
Robot.motorsWrite(-200,-200);
Robot.motorsWrite(-200, -200);
delay(500);
Robot.motorsStop();
}
void goToNext(){
// Turn the robot
void goToNext() {
// Turn the robot
Robot.turn(-90);
Robot.motorsStop();
delay(1000);

View File

@ -1,9 +1,9 @@
/* 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.
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
@ -12,18 +12,18 @@
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 the utility function for ths sketch
// see the details below
#include <utility/RobotTextManager.h>
#include <utility/RobotTextManager.h>
char buffer[20];//for storing user name
void setup(){
void setup() {
//necessary initialization sequence
Robot.begin();
Robot.beginTFT();
@ -31,19 +31,19 @@ void setup(){
// show the logos from the SD card
Robot.displayLogos();
// clear the screen
Robot.clearScreen();
// From now on, display different slides of
// 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(5, 4, 0);
textManager.writeScript(9, 10, 0);
Robot.waitContinue();
delay(500);
@ -59,7 +59,7 @@ void setup(){
//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();
@ -84,56 +84,56 @@ void setup(){
//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);
textManager.writeScript(4, 10, 0);
Robot.waitContinue(BUTTON_LEFT);
Robot.waitContinue(BUTTON_RIGHT);
textManager.showPicture("kt1.bmp", 0, 0);
}
void loop(){
void loop() {
// do nothing here
}
/**
textManager mostly contains helper functions for
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
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.
Display a script of Hello User example.
Parameters:
script_number: an int value representing the
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,
@ -147,9 +147,9 @@ The ones used in this example:
to access the values later.
Returns:
none;
textManager.writeText(line,column,text):
Display text on the specific line and column.
Display text on the specific line and column.
It's different from Robot.text() as the later
uses pixels for positioning the text.
Parameters:
@ -160,18 +160,18 @@ The ones used in this example:
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
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
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
none
*/