Assign what tones in the function Tone() for drum beats.

In the function tone() , we add notes like A4,B5,C6 or etc to get appropriate tones, is it possible to get drum sounds by using;

tone(PIN, x); delay(25); The delay is quite small as its gonna produce beats noTone(PIN);

or something similar? and with that what should the notes x be so that it sounds like drum beats and cymbals etc?

Thanks I am planning on using this with capsense to make a kind of capsense drum synth

The tone function causes the pin to be turned on and off at a high frequency. The value of x defines that frequency. There is a (defined) range of frequencies that the tone function can generate. The duration of the tine is defined by the delay(), and is completely separate from the frequency.

You are allowed, even encouraged, to create a loop that calls tone(), delay(), and noTone() with varying frequencies, to listen to the results.

Personally, I don't think you are going to find that tone can reproduce a drum sound, since drums are vibrating large amounts of material, unlike a piano string, so the frequency is quite low (below the lower limit of the tone() function. But, it really depends on the type of drum you are trying to emulate.

Im just trying to make frequencies (as u said) of bass, snare, tom-tom(middle, low and high), a few cymbals so I will try to get a frequency to set these and once I get it I will post it here :) thanks

Musical instruments, including drums and cymbals (*), generate a large number of different frequencies all at the same time. The tone function can't generate these kinds of sound because it only generates one frequency at a time.

Pete (*) Victor Borge, when referring to the tympanist in an orchestra, said "What does he know about music?" XD

You can't make a silk purse out of a sow's ear.

Sound synthesis is an interesting subject :slight_smile:

Here is a little example I quickly whipped together. Maybe it could serve as a basis for further experiments?

const int pin = 9;

void setup() {                
  pinMode(pin, OUTPUT);
}

void pitchshift() {
  for( int i = 0; i < 1000; i++ ) {
    long micros = 1000 + i;
    digitalWrite(pin, HIGH);
    delayMicroseconds(micros);
    digitalWrite(pin, LOW);
    delayMicroseconds(micros);
  }
}

void boom(int len) {
  for( int i = 0; i < len; i++ ) {
    float t = (float)i / (float)len;
    digitalWrite(pin, random(10) < (1.0f-t)*5 ? HIGH : LOW);
    delay(1);
  }
}

void loop() {
  pitchshift();
  boom(400);
  delay(5000);
}

The sketch generates a simple square wave whose pitch is shifted. Then some random noise is generated.

I think with a little work this could be modified to sound like a drum in the spirit of Rob Hubbard and other masters of chip music. Basically the idea is to first generate a short segment of high pitched noise followed by squave wave whose frequency slides down.