RockBand KickPedal help please!

Hello all,

I am new to the Arduino world but have ambitious ideas. I am currently trying to build a circuit to help me build a new kick pedal for my rock band drums. From what I have learned the kick pedal provided by the company uses a Rare Earth Magnet and a N/O Reed Switch to close the circuit. I was able to build that with a 8mm audio cable soldered to the cable and magnet placed in the hammer (First attached image). But what I want to do is use the Arduino Uno to make a double kick pedal. So what I need to happen is when one hammer closes one circuit it only fires on a close signal and re-opens even if the magnet is still close enough to keep it closed so that the second hammer can do the same. Here is the code I have so far and the circuit. Sorry if it sounds confusing and thanks for any help.

int switchstate = 0;

void setup(){

  pinMode(3,OUTPUT);

  pinMode(2,INPUT);
}

void loop(){

  switchstate = digitalRead(2);

  if (switchstate == LOW) {
    digitalWrite(3, HIGH);
  }
  else {
    digitalWrite(3, LOW);
  }
}

A photo does not give a good indication of how it is wired. Please draw a clear circuit and post a photo.

You have used a pull down R on you proto board. Many "how to" circuits do it that way. The better way is to use pull-up R's. The reason being that it reduces the possibility of shorting the 5v rail. The Arduino also has inbuilt pull-up R's so can save some wiring.

Do you want to

Read a single activation of the switch (reed switch)
Output a pulse to the hammer
Output a second pulse to the hammer
Wait for the next switch activation

Weedpharma

Thank you for taking the time to help, let me see what I can do for you.

Ok i'm not the best at drawing a schematic and I wouldn't want to mistranslate what i'm doing. So I have cleaned up the breadboard for easier viewing. What I have is pin 4 connected to the 8mm audio jack and pin 2 connected to the reed switch and the LED is just an indicator (I don't need it if it makes things eaiser). Sorry but I should of been more clear, but I will have two reed switches and two hammers with magnets in them. What I need to happen is basicly make the reed switches act like push buttons. So even is I have the one hammer close enough to the reed to tell the game one kick has happened, I should be able to still use the second (other) one to close the circuit again and tell the game I have kicked again.

Picture Link:
Imgur

I am still having problems with the sequence required.

In summary

Two reed switches
Close first reed switch and pulse triggers hammer.
If no more closures return to standby
If second reed switch closes (even if first still closed) trigger hammer again.

There appears to be two hammers. How do you want to handle them?

What closes the reed switches? Where is the second reed in your circuit?

Please give a description in clear sequential steps. This will then be the basis for your program logic.

Weedpharma

Not a prob, lets see if this helps.

Two reed switches - Yes
Close first reed switch and pulse triggers hammer- Hammer is the trigger, hammer will have magnet in it.
If no more closures return to standby - Maybe. I need it to be in standby as fast as possible after a trigger(Hammer with magnet in it) has closed the reed.
If second reed switch closes (even if first still closed) trigger hammer again. - Yes

There appears to be two hammers. How do you want to handle them? - Yes, they are my triggering devices. This part you prob dont have to worry about as much. I more so need help with the circuit and logic more so.

What closes the reed switches? Where is the second reed in your circuit? - The hammer with magnets in them. Sorry I didnt add it yet. I figured if I could get one to act the way I need adding a second one would be pretty easy, but I can add it now if you think it will help.

Please give a description in clear sequential steps. This will then be the basis for your program logic. -

  1. Default is both hammers/magnets have the reeds in a physical closed state.
  2. I remove one or the other hammer/magnets
  3. I re-apply one or the other hammer/magnets
  4. Game sees a closed circuit/kick for a split second and then logically opens up allowing the other hammer/magnet to do the same on the other reed even if the first hammer/magnet is still physically closing the first reed.

I am still confused.

With two hammers, is there one reed for each hammer? If so can we simplify and only talk about one hammer and one reed.

If two reeds for each hammer, where are they and how are they operated. Can we still talk about one hammer or do you want two hammers to operate in the code. (Not two separate individual hammer controls).

What activates the hammer the first time? A foot? What closes the second reed?

Can you supply a clear photo of the reed switches in the location they will be on the hammers.

Weedpharma

Sorry, thanks for sticking with me here.

There is one reed for each hammer. I have no problem just talking about one hammer and one reed. I will be able to supply a clear pick here soon once I get off work in a couple hours. Here is a pick on I found on google that gives you an idea of whats going on. Usually when you drum its easier to keep you foot down on the pedal when its not in use. So if thats the case then the little white part “the hammer” is touching the sensor area which keeps the circuit closed. I want to be able to keep my foot down and the circuit tell the game the circuit is not closed. It should only show closed when I initially put my foot down to make the hammer contact the sensor area.

This all comes down to a "state machine". You want to sense the change of switch state to operated, do whatever and wait until it is unoperated and reoperated.

If switch is operated and flag not set
set flag
Do whatever // Do this once per switch operation
Else
If switch is not operated
Reset flag

Continue program

Weedpharma

That sounds about right. And that where im hoping you can help more. I have gone through the starter kit and I know some basics. Do you have a suggestion on my code? And is there anything that looks wrong with my circuit? Thanks.

So here is what I came up with. The issue so far I have with this is the else statement at the end. I keep getting an error saying "else without a previous if"

#define S_IDLE 1
#define S_KICKON 2
#define S_WAITON 3
#define S_KICKOFF 4

int Reed = 0;

void setup()
{
  pinMode(4,OUTPUT);
  pinMode(2,INPUT);
}

void loop()
{
  Reed = digitalRead(2);
  static int state = S_IDLE; // Start in idle state
  
  switch(state)
  {
    case S_IDLE: // Start state do nothing
      if (Reed == HIGH){ // If Magnet is near Reed
      state = S_KICKON;
      }
      break;
    case S_KICKON: // Pedal is down for first time, game hears kick
      digitalWrite(4,HIGH); // 8mm is hearing constant kick
        state = S_WAITON;
      break;
    case S_WAITON: // Pedal is down and wanting to wait, game heard kick
      if (Reed == HIGH) { // If Magnet is near Reed
        state = S_KICKOFF;
      }
      break;
    case S_KICKOFF: // Pedal is down and waiting, game hears nothing
      digitalWrite(4,LOW); // 8mm is hearing nothing
      if (Reed == LOW); { // If Magnet is away from Reed
        digitalWrite(4,LOW);
      }
      else {
        state = S_KICKON;
      }
  }
}

Else without if is due to the ";" on the if..... line.

The preferred method of using switches is to have a pull-up R and use the switch to gnd. This allows using the internal pull-up R and saves some wiring.

May have time later to go through code.

Weedpharma

Case() is usually used to select from possible values of input. Such as input a value from 1 to 10 then do something for each possible number.

Do not hard code pin numbers as in digitalRead(2). It makes it harder to change later and harder to follow the code.

Do a search on "state machine"

Weedpharma

Is there a difference in Finite State Machines and State Machines? Here is the link I used to help me build the code I have.http://hacking.majenko.co.uk/finite-state-machine

Interesting example. It is not something I have seen before.

As I am not an experienced programmer, I will leave it to others to analyse and help with the program.

Weedpharma