Arduino Robot is a development platform on wheels.
First in the arduino is a code called disco-pot, in which the robot is dancing and the music belongs to.
The code had to change own style.
The original code:
#include <ArduinoRobot.h> // include the robot library
/* 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
}
Anniina's embedded blog
torstai 27. maaliskuuta 2014
torstai 20. maaliskuuta 2014
I woke up at eight o'clock, because the alarm didn't work. I drank a two cup of coffee and ate a sandwich. Then I had to go quickly letting the horses out of the stables and I gave them gras and water (I have two horses, whose names are Kassu and Susu), after that I went to school quickly. I came to school by car. I had to drive a Toyota Carina because the second of my car's, Toyota Celica, is a project car that should be ready by the summer. My father renovate it, I'll focus on more the interior of the vehicle.
It rained a lot of snow in the outdoors. I think that the snow has already become enough.
Morning classes I did arduino project called "knock lock". I could not get it to work right away.
Half past nine was the coffee break. I bought coffee from gas station called st1.
After the coffee break we had two hours of English.
English lessons after the lunch break. The afternoon was again arduino. Knock lock began to work.
The sensor tag was just too sensitive.
The school day ended at half past two. I had to drive very carefully because it was very slippery, especially because the car had bad winter tires.
After getting home I gave the horses gras and water, then I sorted advertisements. I ate the food before we went to deliver the advertisements.
After delivering the advertisements I watched Salatut Elämät on TV. Salatut Elämät is my favorite series.
At eight o'clock, I went to clean up the stables. Then I put food and water in the stable ready for horses. After that I put the horses in the stable.
Later I went to the shower and I watched series called Twin Peaks. Then I went to sleep.
It rained a lot of snow in the outdoors. I think that the snow has already become enough.
Morning classes I did arduino project called "knock lock". I could not get it to work right away.
Half past nine was the coffee break. I bought coffee from gas station called st1.
After the coffee break we had two hours of English.
English lessons after the lunch break. The afternoon was again arduino. Knock lock began to work.
The sensor tag was just too sensitive.
The school day ended at half past two. I had to drive very carefully because it was very slippery, especially because the car had bad winter tires.
After getting home I gave the horses gras and water, then I sorted advertisements. I ate the food before we went to deliver the advertisements.
After delivering the advertisements I watched Salatut Elämät on TV. Salatut Elämät is my favorite series.
At eight o'clock, I went to clean up the stables. Then I put food and water in the stable ready for horses. After that I put the horses in the stable.
Later I went to the shower and I watched series called Twin Peaks. Then I went to sleep.
keskiviikko 19. helmikuuta 2014
Today I started to write a blog. In the blog I write about Arduino. Arduino is an open hardware microcontroller-based electronics platform and programming environment.
I have already made different connections and programming from Arduino.
Arduino's homepage: http://www.arduino.cc/
I have already made different connections and programming from Arduino.
Arduino's homepage: http://www.arduino.cc/
Empty arduino, where there are no connections
Arduino with an incomplete program.
Tilaa:
Blogitekstit (Atom)