Created
November 14, 2015 07:29
-
-
Save marcovannoord/bf5e34aef6a17b8bcdc8 to your computer and use it in GitHub Desktop.
tonekeyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Piezo | |
This example shows how to run a Piezo Buzzer on pin 9 | |
using the analogWrite() function. | |
It beeps 3 times fast at startup, waits a second then beeps continuously | |
at a slower pace | |
*/ | |
void setup() { | |
// speaker aansluiten tussen pin 9 en GND | |
pinMode(9, OUTPUT); | |
beep(50); | |
beep(50); | |
beep(50); | |
delay(1000); | |
} | |
void loop() { | |
beep(200); | |
} | |
void beep(unsigned char delayms){ | |
analogWrite(9, 20); // Almost any value can be used except 0 and 255 | |
// experiment to get the best tone | |
delay(delayms); // wait for a delayms ms | |
analogWrite(9, 0); // 0 turns it off | |
delay(delayms); // wait for a delayms ms | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment