0

is there another way to replace delayMicroseconds(BassTab[note_index]) as I cannot have delays in my loop due to the need of having multi-tasking in my sketch.

Grove speaker: http://www.seeedstudio.com/depot/Grove-Speaker-p-1445.html

/*macro definition of Speaker pin*/
#define SPEAKER 8
int BassTab[]={1911,1702,1516,1431,1275,1136,1012};//bass 1~7
void setup() 
{
 pinMode(SPEAKER,OUTPUT);
 digitalWrite(SPEAKER,LOW);
}
void loop()
{
 sound(5);
 delay(5000); //Wait 5second and play the sound again
}
void sound(uint8_t note_index)
{
 for(int i=0;i<100;i++) 
 {
 digitalWrite(SPEAKER,HIGH);
 delayMicroseconds(BassTab[note_index]);
 digitalWrite(SPEAKER,LOW);
 delayMicroseconds(BassTab[note_index]);
 }
}
asked Sep 4, 2015 at 12:30

1 Answer 1

1

It's just a small amplifier and speaker - what you put into the SIG pin gets amplified and sent out the speaker.

Instead of doing the audio generation manually like that I would suggest using the tone() function which will generate an audio tone at a desired frequency in the background.

answered Sep 4, 2015 at 12:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.