Go Down

Topic: "beep-beep" variable (Read 172 times) previous topic - next topic

Matteo1991

Jun 11, 2018, 10:51 am Last Edit: Jun 11, 2018, 10:52 am by Matteo1991
Hi,

i should generate a "beep-beep" from 1Hz to 20Hz. Frequency depend of result of an calculation(reference value!). The sound of beep depend of this value:
if value>reference_value ==> sound_1
if value<reference_value ==> sound_1


if value = 255 ==> sound_1 whit 20HZ of frequency
if value = reference_value ==> no beep
if value = 0 ==> sound_2 whit 20HZ of frequency


For example:

Code: [Select]

float value;
in reference_value = 125;

value = digitalRead(A0); //example

if (value>reference_value) [...] //sound_1!
if (value<reference_value) [...] //sound_2!

//frequncy_of_beep [...] //depend of value/reference_value


This "function" coludn't is in a main program (i'm thinking of multitasking....).
sholud i use a second microcontroller (slave of main arduino)?????


Grumpy_Mike

Quote
sholud i use a second microcontroller (slave of main arduino)
No.

You can't here frequencies lower than 20HZ so this bit is not going to work.
Quote
i should generate a "beep-beep" from 1Hz to 20Hz. Frequency depend of result of an calculation
Post all your code if you want help, say what the code does and what you want it to do.

Matteo1991

#2
Jun 11, 2018, 11:25 am Last Edit: Jun 11, 2018, 11:28 am by Matteo1991
Post all your code if you want help, say what the code does and what you want it to do.
i don't wrote a code because i don't know "how". This is the problem!
 I know that frequency less than 20HZ isn't be generated (like tone());

the ask is: how to generate a beep with different frequency and different sound????
 Should I use two buzzers?
In this mode, i can use two counter of timer to generate two different interrupts (different prescaler)....

Grumpy_Mike

Quote
the ask is: how to generate a beep with different frequency and different sound?
When you say a "beep-beep" sound that implies you are going to listen to the sound, in this case you can't so what are you going to do with the signal?

"different frequency" is understandable but "different sound" is not, do you mean the tambrar? In which case it is meaningless for sub audio tones.

At such low frequencies you can use the "blink without delay" example code found in the Arduino's IDE to generate two "tones" at once.

Quote
i don't wrote a code because i don't know "how".
So how do you expect to do your project? Are you expecting some one to write the code for you?

DVDdoug

Quote
i should generate a "beep-beep" from 1Hz to 20Hz.
I assume that's the on/off frequency, not the audio frequency?


Quote
i don't wrote a code because i don't know "how". This is the problem!
If your audio frequency is in the range of tone() it shouldn't be too hard to modify the Blink example to get a "beep - beep" sound.   If you're "multi-tasking" and delay() is going to mess-up whatever-else your program is doing, start with the Blink Without Delay example.

Then, add an if-statement to turn the beeping on or off.  The Button Example shows how a simple if-statement works.

Once that works, you should be able to duplicate that code with a different if-condition and a different beep sound.   (You may need some additional and/or logic in case both if-conditions can be true.)


--------------------------------------------------------------------------------------
Quote
don't wrote a code because i don't know "how". This is the problem!
Programming is NOT EASY!   But if you're going to learn, the Arduino is one of the easiest ways to get started!   (The BEST way to learn ANYTHNG is take a class.*)

Don't try to write the whole program at once.  Start-out with the smallest/simplest program and then "develop" your code by writing one or two lines of code at time, test-compiling and test-running as you go.    It's often helpful to send-out Serial.print() messages so you can "see" variables or you can "see" what the program is doing.   

Even professional programmers don't write the whole program at once.  They write and test in sections.

It's usually better to work on the input & output separately.   For example, a beeper is output and you can write the for the beeper first and test the beeper software & hardware totally under software-control (without any input).    Then you can add the switches/buttons/pots, or whatever controls the beeper and work on the software for it.

It's up to you what you want to work-on first.   You might what to start with whatever is easy, or you might want to start with something that needs experimentation...  If you're not sure if the beeper is going to "sound right" or if it's going be loud enough, etc., you might want to experiment with that part first.   Or sometimes you need one thing working before you can test another thing.

Sometimes, you might want to write some test-code that won't end-up in your final project.   And, sometimes you might build hardware that's not part of your final project...   Maybe a pot to simulate a temperature sensor, or LEDs in place of motors, etc. 




* The biggest thing you're missing when you try to teach yourself from books or from the Internet, is that they usually cover the programming language  without teaching you the concepts or "how to program".   

I think  most people on this forum learned on their own.  I've had a couple of programming classes but I learned C/C++ from a book (the Arduino stuff from the Internet) but I'm not an expert propgrammer.

Most professional programmers took programming in college (even if they didn't major in computer science).   I've known one professional programmer who didn't graduate from high school.    I don't know if he ever took a programming class or if he was completely self-taught.  (And, I've known one electrical engineer who didn't have an engineering degree.) 

Matteo1991

#5
Jun 12, 2018, 10:06 am Last Edit: Jun 12, 2018, 10:10 am by Matteo1991
And, I've known one electrical engineer who didn't have an engineering degree. 
i'm electrical engineer! And i know a little bit of programming..... just trivial programming!
i didn't write this firmware because, in this case, i don't have idea of "how" and i know that this isn't elementary!



Grumpy_Mike

Quote
i'm electrical engineer
Then why will you not answer our questions?

Matteo1991

I think that there is a misunderstanding!
I try to explane my question better:
I have to generate a sound with buzzer:
-The frequency of this sound should be proportional of a value;
-Range of this frequency is 10Hz to 30Hz (for example):

frequency = (read_value)/(reference_value);

The Sound of this beep-beep (with calculated frequency) depend of:

if read_value is less than reference_value => sound_1

if read_value is more than reference_value => sound_2

i'm building a variometer: if climb rate is "positive" the beep-beep has a sound_1, if climb rate in "negative" the beep-beep has sound_2.

The frequency depend of climb rate (magnitudo);

do you understand?

p.s. sorry for my english, i don't speak well this language. 



slipstick

You're not making much sense, partly because a frequency of 10Hz is not audible so you can't really call it a sound but at the same time 10-30Hz is too fast to be heard as a beeping rate.

What I think you might mean is two different "beep" sounds, one for what you call sound1 and the other for sound2. You haven't yet said anything about how you plan to make those two different sounds and that's important because you'll find they need different frequencies, but maybe something like 800Hz for sound1 and 200Hz for sound2.

But then when you have those sounds you want them to repeat beep-beep-beep. The choice of sound depends on if the climb rate is positive (sound1) or negative (sound2) and the speed that the beep repeats at (it's easier if you call it SPEED not frequency) depends on the rate of climb or descent. So rapid climb or descent = fast beeping. Is that correct? That's more or less how the varios I've met behave.

You'll probably find that a repeat speed of something like 0.5Hz to 3Hz is more reasonable...much faster than 3Hz and the sound is just a blur.

Steve

Grumpy_Mike

Quote
i'm building a variometer
You wait ten years for a variometer project and two come along at once. There is an other thread in this subject in the Audio section, equally badly explained. Is this a class assignment?

Quote
I have to generate a sound with buzzer:
What sort of buzzer, there are two types, an active type that makes a sound when you apply a fixed voltage, and the passive type that generates a sound only in response to being fed a signal. What type do you have?

As I have been saying for a long time you can't here sounds in the frequency range you say you want. This is a big problem for you and one that you keep not explaining.


zoomx

I have to generate a sound with buzzer:
-The frequency of this sound should be proportional of a value;
-Range of this frequency is 10Hz to 30Hz (for example):
Maybe range can be 500Hz-1000Hz is better.
You can use tone but you can change only frequency.
since the sound should be proportional of a value, you can use map() or you can calculate your linear fit between your values and the range 500-1000 or 10-30 if you need that range.

Go Up