Last active
July 19, 2016 08:20
-
-
Save dmitmel/253facc7891127e0ea55 to your computer and use it in GitHub Desktop.
PMW for Arduino Nano
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
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