Skillnad mellan versioner av "Grove - Speaker"

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
 
(5 mellanliggande versioner av samma användare visas inte)
Rad 1: Rad 1:
 
+
[[Fil:Grove-Speaker.jpg|200px|thumb|right|Grove - Speaker]]
 
 
 
 
  
 
== Kompatibilitet ==
 
== Kompatibilitet ==
Rad 13: Rad 11:
  
 
=== 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 45:
 
     }
 
     }
 
}
 
}
 +
</syntaxhighlight>
  
  
  
 +
== Mer information ==
  
Mer information: http://wiki.seeedstudio.com/Grove-Speaker/
+
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

Grove - Speaker

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/