Skillnad mellan versioner av "Grove - Speaker"
(6 mellanliggande versioner av samma användare visas inte) | |||
Rad 1: | Rad 1: | ||
+ | [[Fil:Grove-Speaker.jpg|200px|thumb|right|Grove - Speaker]] | ||
+ | == Kompatibilitet == | ||
+ | * Arduino | ||
+ | == Port == | ||
+ | * Digital | ||
− | Mer information | + | |
+ | == Exempelkod == | ||
+ | |||
+ | === Arduino === | ||
+ | <syntaxhighlight lang="C++" line> | ||
+ | /*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]); | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | |||
+ | == Mer information == | ||
+ | |||
+ | http://wiki.seeedstudio.com/Grove-Speaker/ | ||
[[Category:Grove]] | [[Category:Grove]] | ||
+ | [[Category:Grove-Actuator]] | ||
+ | [[Category:Kna-Wiki]] |
Nuvarande version från 4 februari 2021 kl. 07.42
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]);
}
}