Skip to content

Commit

Permalink
Merge pull request #15 from grimpel/master
Browse files Browse the repository at this point in the history
fix incorrect PWM range
  • Loading branch information
mcauser committed Mar 31, 2016
2 parents df318fc + e17fe2f commit 032628e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions 01.Basics/Fade/Fade.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

const int ledPin = BUILTIN_LED; // the onboard LED
int brightness = 0; // how bright the LED is (0 = off, 128 = dim, 255 = full)
int brightness = 0; // how bright the LED is (0 = full, 512 = dim, 1023 = off)
int fadeAmount = 5; // how many points to fade the LED by
const int delayMillis = 30; // how long to pause between each loop
const int delayMillis = 10; // how long to pause between each loop

void setup() {
pinMode(ledPin, OUTPUT); // initialize onboard LED as output
Expand All @@ -19,12 +19,12 @@ void loop() {
// increment/decrement the brightness for the next loop
brightness = brightness + fadeAmount;

// limit to 8-bit (0-255)
// limit to 10-bit (0-1023)
if (brightness < 0) brightness = 0;
if (brightness > 255) brightness = 255;
if (brightness > 1023) brightness = 1023;

// reverse the direction of the fading at each end
if (brightness == 0 || brightness == 255) {
if (brightness == 0 || brightness == 1023) {
fadeAmount = -fadeAmount;
}

Expand Down

0 comments on commit 032628e

Please sign in to comment.