Go Down

Topic: How do I record button presses and play them back? (Read 4 times) previous topic - next topic


Hi, I saw this video on youtube of a guy controlling a milling machine using a NES control pad. I'll post a link soon.

I wondered whether the arduino could record a long sequence of button presses, and the amount of time they were pressed, then repeat the sequence at the press of a button. This would eliminate having to translate a CAD file into stepper motor commands, and in essence you would be manually programming the milling machine. You would also need a separate button for record and playback and for moving the machine to its reset position (0,0,0).

I have very limited programming experience, and was wondering what code would be needed to record the input pins while controlling it, then play the stored inputs as outputs to the stepper motors with a single button press. Sorry if this has already been done, but the search feature did not return exactly what I wanted.



Jan 21, 2011, 02:22 pm Last Edit: Jan 21, 2011, 02:22 pm by jimmimak Reason: 1
Here is the link to the NES control pad controlling a milling machine:

My idea must be really simple to do, but I don't know where to start. :-/


It not to dissimilar from a project i'm going to be doing next. A bit different i'm MIDI'ing a only pre MIDI keyboard. It's no standard analog and it's polyphonic so the usual CV rout wouldn't work. Anyway it  involves being able to 'record' the key-press on the keyboard and then also play them back in the same way you would on a games controller i guess. Just on a keyboard you have a lot more keys.

I've decided to unhook the keyboard or keys from the device and replace then with a transistor. The original keys are then fed into the Arduino and in normal mode echo'd straight to the transistor switch. So they act like normal in record mode i will be turning this information into MIDI and sending it to a dedicated MIDI recording device. For play back you are just re-triggering the transistor switches in the pattern you have recorded.

For you you probably want to record it strait into the arduino. this  shouldn't be to difficult as i guess they will be relatively short and not to complicated (in comparison to a piece of music say ) . You going to want to use some kind of array to store incoming key-presses in with a time stamp. Then a way of playing this back


Your project sounds interesting, I like the idea of using the transistors in place of keys.

Another thing that would be useful to me is creating commands for shapes such as circles, curves and angled straight lines as this would be hard to do with a control pad. Then these features could be recalled using different keys on the controller, but thats for future development.  

I'll try and find out about doing it as an array with time stamps. If you have any code for this would you mind posting it here?

I plan to eventually make a milling machine to mill circuit boards and bits of wood and plastic for different projects. I think this method would be the simplest - a cross between a manual and CNC machine!


I wondered whether the arduino could record a long sequence of button presses, and the amount of time they were pressed, then repeat the sequence at the press of a button.

The answer is yes, for some definitions of long and some number of buttons.

The number of buttons is limited by how you read them.

Each time a button release is detected, the button number and duration needs to be stored. If there are less than 255 keys, the key number can be stored in a byte. If the maximum time for a key to be help down is 32 seconds or less, the time can be stored in an int (2 bytes). Otherwise, you need to use a long (4 bytes).

So, from 3 to 6 bytes per press/release. With 2K of SRAM, and not using every last bit of it, you could store 300 to 600 button presses/times.

If you need to store more than that, you need some kind of external storage, such as an SD card.

Go Up