Created
July 5, 2012 08:05
-
-
Save jscrane/3052186 to your computer and use it in GitHub Desktop.
Software PWM for Arduino/ATtiny
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
void spwm(int freq, int pin, int spd) { | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(spd * freq); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(spd * (255 - freq)); | |
} | |
int delay = 15; | |
void loop() { | |
for (int i = 20; i < 240; i++) | |
spwm(i, pin, delay); | |
for (int i = 240; i > 18; i--) | |
spwm(i, pin, delay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment