Hi,
I am in a kind of a rush, looking for a code that creates a metronome tone in simple headphones that are connected to an arduino due. Unfortunately, the function tone() does not work for arduino due, so I looked a while in the forum but couldn't find something that worked.
So I wanted to ask, if someone has a decent code for this purpose. The only thing that I have to change in the future is the frequency of the tone, that's it..
Thanks for your help,
Maitschi
Moved to audio section as here no answers came
This code generates tick-tock on a Teensy 3.2 (a 3.3V processor like Due) without using tone().
// Legends of Zelda - Song Of Storms/Windmill Hut
// coded by Calum
// feel free to edit or change the code
/*
PAH - heavily modified to just do tick/tock
From: http://forum.arduino.cc/index.php?topic=56637.0
*/
int speakerPin = 9; //Speaker or Piezo buzzer on pin 9
void setup(void)
{
pinMode(speakerPin, OUTPUT);
for(int i = 0;i < 5;i++ ) {
tick(speakerPin);
delay(1000);
tock(speakerPin);
delay(1000);
}
}
void loop(void)
{
}
void tick(unsigned char speakerPin)
{
for (int x=0;x<6;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(500);
digitalWrite(speakerPin,LOW);
delayMicroseconds(500);
}
}
void tock(unsigned char speakerPin)
{
for (int x=0;x<3;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(1000);
digitalWrite(speakerPin,LOW);
delayMicroseconds(1000);
}
}
For a metronome, just call either tick() or tock(), whichever sounds better.
I have a piezo speaker wired directly on pin 9.
Pete