Simple programmable toy?

As a kid I remember seeing "robots" that had a simple keypad program system... I think they were put in a program mode, and it stored keypad presses and then played them back as motor drive... eg forward three, forward_right 2, back 4 etc....

I was thinking of making a keypad of 6 directional and perhaps 2 other momentary on buttons, set up as analogue inputs with different resistance per button so I could do the input with only 2 or 3 analogue inputs..

I hope to drive an old RC car - nice & simple and a great way to get the kids interested too.

One of the things I'm not sure of is how to create a program mode and an execute mode.... I was thinking of defining a set of 30 or so variables instruction 1 instruction 2 etc.

As for input I was thinking of holding one of the directional buttons and pressing a "program" button to save the variable (one of 6 for the possible directions) and then an execute button or switch to "play" the variables back to the motor and (I think) voicecoil steering in the donor toy.. but how to create that I have no idea...

The other thing is the playback, my skills are old and very rusty and I was thinking of just creating a giant, ugly "if" series testing each variable until the drive command matched up...

Does anyone have some friendly advice or perhaps knowledge of a link to this sort of project?

Sounds like a pretty ambitious project as a "first" project for someone who has been away from this stuff for a while. I'd try a few simple sketches first to learn Arduino and get into the swing of things.

Then get a keypad, and follow the info on the Arduino site. Then go from there. Life is all a big learning curve. One thing at a time.

Cheers bud, yeah I have been playing heaps...

I'm pretty sure I have the logic for the motor & steering control figured... but the storage & playback of an array has me a little bamboozled.

BigTrak Jr?

Thats exactly the sort of thing I'm hoping to build! Thanks Lakes.

I would suggest using arrays and not variables. This will make things a lot easier.
Suppose you store each command in ‘char’ variable. Then to store up to 30 commands you need an array of 'char’s:

char commands[30];
char commands_num = 0; // this is the actual number of commands

storing commands will look something like this:

// receive the new command here
char new_command = …
// add the command to you commands array
if ( commands_num < 30 )
commands[commands_num] = new_command;
// no space left for commands

Executing the commands will look like:
for(int i=0; i<commands_num; ++i)
char current_command = commands*;*

  • // put here the code to execute the current_command*
    Note, the executing runs from the beginning of the array till the number of commands stored in it in the program mode.

Please use code tags when posting code, so that it doesn't degenerate into italics.

A note about command processing.

You may use if..else or switch statements of course. I suggest more elegant solution using arrays.

If you understand the solution with arrays, then processing commands can be implemented in the similar way. Suppose you have 3 commands. Each command will have its unique id starting form 0 (zero) to 2. You can store a function that will execute the command in the array;

// This function will execute command 0
void exec_command0()

void exec_command1()
// This function will execute command 2
void exec_command2()

// Note that all above functions have the same prototype: they receive void and return void
// We now need to define a type of this functions
typedef void (*command_executor_type)();

// Now we define array of those functions
command_executor_type exec_commands[] =

Now, in order to run the command, according it's id 1. first access the corresponding array entry using '[ ]'. for command with id 0 (zero) it would be exec_commands[0] 2. The entry, stored in the entry of array is function (actually the address of function, but that does not matter). We call functions using '()': exec_commands0;

void loop()
    char curr_command = 0; // get command id here 0-2
    // execute the command