Multiple tones, at multiple rates

Hello!

I have a long variable Dif = 0;

and more comparations like :

  1. if Dif > 0 -- play a tone1 with a delay of x(miliseconds) until Dif changes to other long variable
  2. if Dif > 10 -- play a tone23 with a delay of y(miliseconds) until Dif changes again
  3. if Dif > 20 -- play a tone31 with a delay of z(miliseconds) until Dif changes again maybe to 5 and need to go at comparation 1
    ..............
    ...............
    ..............
  4. if Dif > 90 -- play a tone44 continuous until Dif changes again ....

I have a PiezzoSpeaker on digital pin number 8.
Dif it is calculated in a function calculateDif();

Thank's for help

P.S. I am new in Arduino and programming

I forgot to say, that the delay of tones is bigger at the beginning, and shorter, proportional with Dif, until is playing continuous at comparator 10)

Example:
it is like if Dif >20 then Bip Bip, Dif changes to > 60 and tone changes to Bip Bip Bip Bip Bip Bip, again Dif changes to > 90, tones goes biiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiip continuous , Dif changes to > 60 and again the tone Bip Bip Bip Bip Bip Bip

Hi!

Sorry to say that but you'll need to explain more clearly your need here... there is no question, and very few details on what you are doing. Try to reformulate, and add a question?

as far as you present it, to me it looks like you're trying to make something which behaves like a bomb in the Counter Strike video game :slight_smile:

:slight_smile: I don,t like bombs. Sorry for my English first. It all about a acoustic variometer for paragliding.

Dif is the velocity speed. So in void loop(void) I measure the speed witch may results :

Dif = 0.5 m/s
Dif = 3 m/s
etc etc

How can I make a constant sound on digital pin 8 of PiezzoSpeaker with different sounds tones for each speed?

tone1 for 0 to o.5 speeds
tone2 for speeds between 0 and 1m/s
tone3 for speeds between 1m/s to 2m/s
tone4 for speeds between 2m/s to 3m/s

......
......
......
tonex for speeds between 9m/s to 10m/s
continuous tone for speeds over 10m/s

Ok I see, my cousin used one when he took me for my "virgin flight". Was awesome indeed. When we were finding wind going upwards, the sound of his stuff was buzzing hell :=)

A) Now first question that you have to ask yourself: what is the "sample rate" you need for your equipment?

how often do you want to update the bip information? To my memory, when you fly, sometimes there is "bursts" that last half a second and that would be nive to be detected. Like when you enter the thermal upward wind that makes you climb. It does not last long.

This means that you need to be able to update the information from your sensor quite fast, four times a second at least would be good from a rough point of view. but maybe it's more.

B) Program structure:
Structure would be simple: a background task that generates the tone beep at a specified rate, and a main task that acquires the acceleration sensor data, and updates the rate accordingly.

C) About the tone : according to the equipment I am aware off, you don't want the frequency of the tone of the "bip" to change, you want to have the rate at the one a "beep" is heared (like once a second, two times a second, etc... up to continuous).

Now, rouglhly, the lowest rate would be once every second, and the highest being continuous tone. The frequency of the "bip" is around 1.5kHz i believe, so you may use the Tone(1500) as a tone generation.

This meanse that i would use an interrupt with a Timer to generate the "Beep" during half a second, and use the main loop to onlycheck for the sensor data, and update the rate at the one the big is generated accordingly.

Maybe check out my project, were I managed to get 8 tones using timers.

https://github.com/Beat707/Beat707-SY-LE

Wk

My system use an Arduino Pro Mini 3.3v(Atmega328p-au) with lipo battery, A piezzospeaker, and one Bosch Sensortec BMP085 (http://www.sparkfun.com/products/9694) witch I set it up at ultra high resolution mode(arround 35 samples/s) and can perform 128 sample/7s in standard mode.

I've heard some Varios with different rates and different tones too. I wold like to do one with this tone changing.

I was thinking to generate tones(tone_v) with "map" where vario is vertical velocity in cm:

if (vario > 40)
{
tone_v = map(vario, 41, 1500, 2000, 4800); //between 41cm and 1500cm generate tone from 2000Hz to 4800Hz
}
else if ((vario >= -200) && (vario <= 40))
{
noTone(speakerPin); //no sound
}
else if (vario <= -400)
{
tone_v = 400; // low tone if sinking at -400cm
}
else if (vario <= -200)
{
tone_v = 600; // very low tone if sinking at -600cm
}

This calculations are made in the main loop. How can I play tone() with this results, in background?