# Is it possible to add a piezo buzzer to a counter

Is it possible to add a piezo buzzer to a counter:

my example:

(countD<70)

so 1 melody at =0 2nd melody 10,20,30,40,50,60 3rd melody 70

This is what I was playing around with:

if (countD=0)
buzz(2, 2500, 500);
++counter;


putting into this:

    if (countD<70)
{
if (countB<10) {
digitalWrite(ledArray2[countB],LOW);
}
if (++countB>=10) countB=0; // For some reason changing this from 20 to 10 makes array not long pause
if (countB<10) {
digitalWrite(ledArray2[countB],HIGH);
}
countD++;
}
}
}
}


Any ideas if its possible?, Im sure it is but I cant find any documentation to help me.

so does this look okay?? 2500, 4000, 6000 I assume is the pitch or tone? so we get one melody for 0 and the second melody from 10-60 third dif melody on 70

 if (countD<70)

if((countD) == 0) buzz(2, 2500, 500);
if((countD % 10) == 10 - 60) buzz(2, 4000, 500);
if((countD % 10) == 70) buzz(2, 6000, 500);
{
if (countB<10) {


Edit 2:

void buzz()

{
if(((countD % 10) == 0)) && ((countD > 10) && (countD < 70)))
{
buzz(2, 4000, 500);
}
else if((countD % 70) == 0)
{
buzz(2, 6000, 500);
}}

-
I'm sorry, Ilias, but I think you'll understand why I can't answer your question. –  stevenvh Aug 18 '12 at 15:28
lol, Thats alright steven. Sorry for get angry but this stuff was getting to me considering I was up till 5AM each night trying to sort this stuff out and because I have mild dyslexia makes it twice a difficult so you can see why I got frustrated and angry. –  Mr Men Aug 18 '12 at 15:52
Apologies accepted. Just understand that we don't tolerate language like that, not towards me nor anyone else. –  stevenvh Aug 18 '12 at 15:56
Hmmm, just noticed that - hopefully things will be better this time around ;-) –  Oli Glaser Aug 18 '12 at 18:25

Yes, just write your buzz() routine and call it on certain intervals of your count variable.

If you want it to be every 10 counts, then do something like:

if((countD % 10) == 0) buzz(2, 2500, 500);

EDIT

The updated code won't work as intended. The % or "modulo"operator returns the remainder of division by the number. So e.g. 8 % 2 = 0 as 2 goes into 8 exactly. 8 % 3 = 2, as 2 only goes twice into 8 with remainder 2.
So you can see that the result can not be higher than the modulo value, so countD % 10 == 70 will never be true. If you want it to buzz on every 70th count as well, use if ((countD % 70) == 0) buzz(2, 6000, 500); - this will buzz on the 70th count, 140th count, 210th count and so on.

If you need to specify every 10th count between certain values, then combine the mod with an and logic check like so:

if(((countD % 10) == 0)) && ((countD > 10) && (countD < 70))) buzz(2, 4000, 500);

-
Thanks, I tried something but Im way off, but got the idea. I edited the post can you take a we peek at the end for me to see how I implement it. Thank you –  Mr Men Aug 18 '12 at 15:49
It's not quite right, see edits to answer. –  Oli Glaser Aug 18 '12 at 16:25
I think I understand is my new edited within a routine correct? I also took out the first buzz as I think I need this a few seconds before the countD starts. –  Mr Men Aug 18 '12 at 17:23
Yes, that looks okay - note that I don't know if the buzz() arguments are correct as I don't use Arduino (I'm guessing it's a provided routine rather than one you wrote yourself), but I'm sure there's plenty of info on how to use it if it's part of a library - just check the documentation. –  Oli Glaser Aug 18 '12 at 18:20
I dont know I was just using that as the variable for the function. This is what I used buzz from if anyones interested faludi.com/itp/arduino/buzzer_example.pde –  Mr Men Aug 18 '12 at 18:53
show 1 more comment