Skillnad mellan versioner av "Grove - Speaker"
Rad 13: | Rad 13: | ||
=== Arduino === | === Arduino === | ||
− | + | <syntaxhighlight lang="C" line> | |
/*macro definition of Speaker pin*/ | /*macro definition of Speaker pin*/ | ||
#define SPEAKER 3 | #define SPEAKER 3 | ||
Rad 47: | Rad 47: | ||
} | } | ||
} | } | ||
− | + | </syntaxhighlight> | |
Versionen från 26 oktober 2018 kl. 13.12
Innehåll
Kompatibilitet
- Arduino
Port
- Digital
Exempelkod
Arduino
/*macro definition of Speaker pin*/
#define SPEAKER 3
int BassTab[]={1911,1702,1516,1431,1275,1136,1012};//bass 1~7
void setup()
{
pinInit();
}
void loop()
{
/*sound bass 1~7*/
for(int note_index=0;note_index<7;note_index++)
{
sound(note_index);
delay(500);
}
}
void pinInit()
{
pinMode(SPEAKER,OUTPUT);
digitalWrite(SPEAKER,LOW);
}
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]);
}
}
Mer information: http://wiki.seeedstudio.com/Grove-Speaker/