DUE and DAC0 analogWrite beep tone

Hi,
I am making this "phone" project and thinking - how can one change the beep tone from analogWrite DAC0?
Right now, my old phone "pressed button beep" is as follows:

void buttonBeep(){
      for (int j = 0; j < 124; j++) {
        for (int i = 0; i < 124; i++)
          analogWrite(DAC0, i);
      }
}

Which is not deep enough.
I've tried different frequencies, but it does not sound that much different. And I cannot really find a proper guide on what are the possibilities with DAC0 tone. Maybe someone can guide me a bit?
Thanks!

Well, "deep" usually means low frequency, so all you need to do is slow the loop down.
Oh, but then, you said,
"I've tried different frequencies, but it does not sound that much different."
So the problem now is that we can't really tell what fault you have with the existing sound. That is key to improving it...
You now have a "sawtooth" wave, you could make it a "triangle"...

void buttonBeep(){
      for (int j = 0; j < 124; j++) {
        for (int i = 0; i < 124; i++)
          analogWrite(DAC0, i);
        for (int i = 124; i >= 0; i--)
          analogWrite(DAC0, i);
      }
}

Thanks a bunch! I haven't tested but hopefully it would work better :slight_smile:
But I still don't really understand how we change the frequency (a tone or pitch if you will) of a DAC? Now we have increasing-decreasing tone (triange?). How to keep in the same frequency?
As I read through more forums I kinda understood that we can use DAC like that:

analogWrite(DAC0, x);
//x = 0 - 255

Where x would be a different voltage sent to DAC. Different voltage = different frequancy?
But when trying the line above - nothing can be heard :confused:

I need "a humming sound" for background when picking up the phone, which is also pretty difficult to achieve :thinking:

Perhaps:

void buttonBeep(){
      for (int j = 0; j < 124; j++) {
        for (int i = 0; i < 124; i+=2) // step 2 at a time.
          analogWrite(DAC0, i);
      }
}

[/quote]

Where did you get the idea, the code? It seems like you don't really understand how works. Do you understand at least, how the 'for' loops work? Try this:

void buttonBeep(){
      for (int j = 0; j < 124; j++) {
        for (int i = 0; i < 124; i++)
         Serial.print(j);
         Serial.print(',');
         Serial.println(i);
     }
}

Thanks!
I found the best result with this up-down tone:

void buttonBeep(){
      for (int j = 0; j < 200; j++) {
        for (int i = 0; i < 200; i++)
          analogWrite(DAC0, i);
        for (int i = 200; i >= 0; i--)
          analogWrite(DAC0, i);
      }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.