Storing Input Data and then looping it

Hello guys!

I want to achieve the following: I'm working on a nifty little touchscreen device that works nicely so far. I can read, condition and output the X and Y values.

Now I had the following idea: If I could record the input data of say maximum 2s somwhere (say SRAM or so) and then with the press of a button loop through that data - that would be awesome!! For that reason I could either take the actual touchscreen input or I also still have free analog and digital pins to which I could simply daisychain my output (I use a filter to convert the PWM to DC later in the circuit).

Is it possible to achieve that?
Thanks for your help!

I don't really understand what you want.

You have a touchscreen
You can see where the touchscreen is pressed (am I right?)
You want to record those (x,y) coordinates for 2 seconds

Then you want to loop through these coordinates? What do you mean by 'loop through'? Do you want to display it on the screen? So, like, I draw a circle on the screen, and 2 seconds later the circle is drawn again?

Also, you are talking about outputs. What do you want with the outputs? Also send the (x,y) coordinates to the PWM outputs?

Thanks for your reply, muddy, and sorry for being unclear.

I have a touchscreen attached to my Arduino and I am reading the X and Y coordinates. These coordinates are then conditioned to my needs in the patch and are sent out via two PWM pins. The PWM is then being fed into an analog filter to turn the PWM into DC voltage. With the DC voltage I can control various instruments of mine - in the end I get 0 - 5V output per axis depending on the position of my fingertip.

All of the above is more or less 'live' (disregarding a few miliseconds I reckon). What I am longing for is the opportunity to push a button, the microcontroller starts recording the X input values and the Y input values and stores them on some sort of memory. 2 seconds of storage is enough, I think the sample rate can be somewhere around 50 - 100Hz as I can't move my fingers so fast anyway :slight_smile: I have no idea about resolution. Would the record button be pushed for longer than 2s the recording of the data would simply stop. Then I want another button that, when pressed - overrides any incoming information from the touchscreen and simply goes through the recorded data over and over again - looping it - and sending that out through the PWM pins now.

There is no display involved. This is not for graphic purposes but for musical ones - think KaossPad.

I hope I made myself more clear now.
Thanks!

I suggest you aim to get the resolution of the recorded data similar to the resolution of your position sensing, which is probably determined by the resolution of your touchscreen.

If you only need a couple of hundred samples per channel and two channels then you'd need 400 bytes to store each value as 8 bits or 800 bytes to store each value as 16 bits. Both of those are well within the memory provided by an Arduino UNO, so I suggest you find out how much memory you have free when your sketch runs and see whether you have enough for this additional data. If not, see whether there is any way to optimise your existing code to free up enough memory.

Peter, yes that sounds pretty much like what I want to do. I have no idea though on how to process the information so that it can be stored on the memory. Would there be a timer that would "grab" the information in certain intervals and store it into an array? Where could I start looking into storing continouus information? I am totally new to this, so sorry for these basic questions.

osterchrisi:
Would there be a timer that would "grab" the information in certain intervals and store it into an array?

That's the basic idea. Presumably you want to take your samples at regular intervals, and the blink without delay example sketch demonstrates how to execute code at regular intervals. In this case the code to be executed would determine whether there was a recording in progress, or a playback in progress, or nothing. In the recording case it would take a sample value and append to the array; if the array is now full or the recording end time has been reached then it would stop recording. In the playback case it would play back the next sample from the array; if the end of the array has been reached then it would start again at the beginning.

Conceptually, you'd need:

  • An array for each channel to be recorded. The type of the array would be the type that you're using to hold a single sample value.
  • An index value that records the current index into all of these arrays.
  • A state variable that records whether the Arduino is doing recording, playback or nothing.
  • A variable that records the time of the most recent record/playback sample.