Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analogWrite issue #334

Closed
agdl opened this issue Oct 25, 2016 · 2 comments
Closed

analogWrite issue #334

agdl opened this issue Oct 25, 2016 · 2 comments
Labels
Milestone

Comments

@agdl
Copy link
Member

agdl commented Oct 25, 2016

Hi, I found a bug in the analogWrite function. Here the sample sketch I used to reproduce the issue:

int led = 3;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(2, INPUT_PULLUP);
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);

  if(digitalRead(2) == LOW){
    digitalWrite(led, LOW);
    while(true);
  }
}

Basically if you use a pin as PWM and then you use the digitalWrite(pin, LOW); the last PWM value stays on the pin.
Obviously writing analogWrite(pin, 0); the issue disappears

@oqibidipo
Copy link

See #280.

@kitsunami
Copy link

Duplicate to #280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants