Why does this code produce this result?
hi folks,
i'm newbie looking guidance following code. produces intermittent tone (beep, beep, beep) goes on 6 seconds (about 13 beeps). i've played values playtone , duration still receive beeping result. result i'm looking single half-second tone (beep). can guide me here? in advance take time! appreciate it
void playtone(long duration, int freq) {
duration *= 1000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
while (elapsed_time < duration) {
digitalwrite(pinspeaker,high);
delaymicroseconds(period / 2);
digitalwrite(pinspeaker, low);
delaymicroseconds(period / 2);
elapsed_time += (period);
}
}
i'm newbie looking guidance following code. produces intermittent tone (beep, beep, beep) goes on 6 seconds (about 13 beeps). i've played values playtone , duration still receive beeping result. result i'm looking single half-second tone (beep). can guide me here? in advance take time! appreciate it
void playtone(long duration, int freq) {
duration *= 1000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
while (elapsed_time < duration) {
digitalwrite(pinspeaker,high);
delaymicroseconds(period / 2);
digitalwrite(pinspeaker, low);
delaymicroseconds(period / 2);
elapsed_time += (period);
}
}
post code.
Arduino Forum > Using Arduino > Programming Questions > Why does this code produce this result?
arduino
Comments
Post a Comment