code: [select]
#include <arduinorobot.h>
#include <wire.h>
#include <spi.h>
#include <eeprom.h>
int movecount[20];
int motorpower = 255;
int turnspeed = 77;
int sensorvalue = 0;
boolean ismoving = false;
void setup() {
robot.begin();
serial.begin(9600);
robot.beginspeaker();
robot.begintft();
robot.beginsd();
robot.fillscreen(0x0099ff);
robot.drawrect(0,0,128,20, 0xffffff);
robot.fillrect(0,0,128,20, 0xffffff);
robot.stroke(0,0,0);
robot.text(" arduino robot",0, 5);
robot.drawbmp("buttons.bmp",95,127);
}
void loop() {
clearmoves();
addmoves();
delay(1000);
executemoves();
}
void clearmoves() {
for(int = 0; < 20; i++) {
movecount[i]=-1;
}
}
void addmoves() {
robot.stroke(255,255,255);
robot.text("-buttons add moves", 0, 24);
robot.stroke(255,255,255);
robot.text("-middle end input", 0, 33);
robot.drawline(0,45,128,45, 0xffffff);
for(int =0; < 20;) {
int key = robot.keyboardread();
if(key == button_middle) {
break;
} else if(key == button_none) {
continue;
}
movecount[i]=key;
printsequence(i,50);
delay(100);
i++;
}
}
void executemoves() {
for(int =0; < 20; i++) {
switch(movecount[i]) {
case button_left:
turnleft();
break;
case button_right:
turnright();
break;
case button_up:
moveforward();
break;
case button_down:
movebackward();
break;
}
robot.text("performing moves...", 5,70);
robot.stroke(255,0,0);
printsequence(i,86);
delay(1000);
robot.motorsstop();
delay(1000);
robot.stroke(255,255,255);
if(movecount[i] == (-1))
{
robot.text("completed!",5,103);
ismoving = false;
delay(2000);
setup();
break;
}
}
}
void moveforward() {
robot.motorswrite(motorpower, motorpower);
delay(200);
robot.motorsstop();
ismoving = true;
}
void movebackward() {
robot.motorswrite(-motorpower, -motorpower);
delay(200);
robot.motorsstop();
ismoving = true;
}
void turnleft() {
robot.motorswrite(turnspeed, -turnspeed);
ismoving = true;
}
void turnright() {
robot.motorswrite(-turnspeed, turnspeed);
ismoving = true;
}
char keytochar(int key) {
switch(key) {
case button_left:
return '<';
case button_right:
return '>';
case button_up:
return '^';
case button_down:
return 'v';
}
}
void printsequence(int i, int originy) {
robot.text(keytochar(movecount[i]), i%14*8+5, i/14*10+originy);
}
void playmelody() {
char atinymelody[] = "8ef#adb";// play
robot.playmelody(atinymelody);// play melody
}
i working code , robot above. want use eeproms on robot don't know how or use it. i've had examples had no luck. want store move sequences addmoves method , when turn off , on, should retain , perform recent move sequences.
can on how implement this?
bump
Arduino Forum > Using Arduino > Project Guidance > Arduino Robot EEPROMs
arduino
Comments
Post a Comment