Help with a really super simple sequencer?

Hi everyone!

I was wondering if anyone knows how to do this? Pretty much I want to be able to use a sensor and a speaker to do the following:

  1. The user taps a rhythm into the sensor for 5 seconds (analog at present, using an if statement to determine on and off).

  2. The arduino records this rhythm and...

  3. Plays it back in a series of clicks generated by pushing the cone of a speaker in and out. It does this on repeat until...

  4. The user taps in a new rhythm.

I've got the arduino hooked up to the sensor, so that it clicks when the sensor is pressed as follows:

int speakPinA = 13;               // ONE SIDE OF SPEAKER 
int speakPinB = 12;               // OTHER SIDE OF SPEAKER

void setup() {
  // initialize serial communications (for debugging only):
  Serial.begin(9600);
  pinMode(speakPinA, OUTPUT);        // sets the digital pin as output
pinMode(speakPinB, OUTPUT);        // sets the digital pin as output
}

void loop() {
  // read the sensor:
  int sensorReading = analogRead(0);
  // print the sensor reading so you know its range
  Serial.println(sensorReading);
  
  if (sensorReading > 500){
    digitalWrite(speakPinA, HIGH);   // pushes speaker/piezo cone out
  digitalWrite(speakPinB, LOW);
}
else
{
  digitalWrite(speakPinA, LOW);    // pulls speaker/piezo cone in
  digitalWrite(speakPinB, HIGH);
}
 

}

does anyone know if it is possible to use arduino to record and playback automatically in the way i'm describing?

Yes it is possible but it is a much more difficult project than you think. The RAM in an arduino is limited and so the time resolution / length of recording possible is not as much as you would like.

One way of doing it is to note the time differences (use "millis()")between taps, and store those.
If you stored them as just "unsigned int"s (allowing the gaps to be up to 65 seconds long) you'd be able to store a couple of hundred events, maybe.

Not as easy as it sounds (forgive the pun) as Mike said.

Ah really? That's a shame. thanks for the advice! I'm really very new to all this. I found this code, which looks promising:

http://corticalcafe.com/hardware/arduino/DrumMachine.pde

Which seems to be a bit overkill for what I want. Plus it uses capacitive sensors as inputs not pressure sensors, so I'm really not sure how to modify it for just one pressure sensor!

i'm thinking space might not be a problem if i overwrite the data each time with a new sequence?

i'm thinking space might not be a problem if i overwrite the data each time with a new sequence

I think that's a given.

The sample code is a pretty good starting point, changing the "beats" array to be unsigned int, and a bit smaller (how many beats can you really get in 5 seconds? 20 per second, tops?).

Start simple, just writing stuff to detect the taps reliably, then start timing them and noting the time since the last tap.
have fun.

Thanks for the advice! :smiley:

I'll have a bit of a play with the code with my clumsy noobish fingers. i guess if need to ask what "unsigned int" means then i'm probably going to struggle...

You might want to give this 'secret knock detecting door lock' a look.

http://grathio.com/2009/11/secret-knock-detecting-door-lock.html

He has got a way to record a sequence of knocks for his Arduino controlled lock, and his code and instructions are at that link.

HTH
GB

Ah! excellent! This looks really promising. really cool project too! Thanks so much. I'll have a go at this tomorrow and post back the code if i manage it.