This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
DINORUN/play.ino
2026-03-01 17:41:24 +09:00

13 lines
411 B
C++

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);
}
}