最初コミット
This commit is contained in:
12
play.ino
Normal file
12
play.ino
Normal file
@@ -0,0 +1,12 @@
|
||||
void play(byte pin, unsigned int frequency, byte duty, unsigned long duration) {
|
||||
unsigned long period = 1000000UL / frequency;
|
||||
unsigned long high = period * duty / 100UL;
|
||||
unsigned long low = period - high;
|
||||
|
||||
for (unsigned long i = 0; i < duration * 1000UL; i += period) {
|
||||
digitalWrite(pin, HIGH);
|
||||
delayMicroseconds(high);
|
||||
digitalWrite(pin, LOW);
|
||||
delayMicroseconds(low);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user