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]);
  }
}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.