Skip to content

Instantly share code, notes, and snippets.

@jscrane
Created July 5, 2012 08:05
Show Gist options
  • Save jscrane/3052186 to your computer and use it in GitHub Desktop.
Save jscrane/3052186 to your computer and use it in GitHub Desktop.
Software PWM for Arduino/ATtiny
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