Skip to content

Instantly share code, notes, and snippets.

@dmitmel
Last active July 19, 2016 08:20
Show Gist options
  • Save dmitmel/253facc7891127e0ea55 to your computer and use it in GitHub Desktop.
Save dmitmel/253facc7891127e0ea55 to your computer and use it in GitHub Desktop.
PMW for Arduino Nano
unsigned int counter = 0;
unsigned int maxCounter = 255;
void pmw(unsigned int pin, unsigned int power) {
if (counter > power) {
digitalWrite(pin, HIGH);
}
if (counter < power) {
digitalWrite(pin, LOW);
}
counter++;
if (counter > maxCounter) {
counter = 0;
}
}
void setup() {
pinMode(17, OUTPUT);
}
void loop() {
for (int i = 0; i < 255; i++) {
pmw(17, i);
delay(10);
}
delay(1000);
for (int i = 0; i < 255; i++) {
pmw(17, i);
delay(10);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment