Skip to content

PWM and tone() incompatibility #4349

Closed
Closed
@davidevertuani

Description

@davidevertuani

Basic Infos

Hardware

Hardware: NodeMCU ESP8266
Core Version: 2.4.0

Description

Hi. I'm having trouble using tone() and analogWrite() on the NodeMCU ESP8266.
Calling only tone() works fine, however calling analogWrite() on another pin, setting it to LOW and then calling tone() (on a different pin) only produces an annoying noise.

Sketch

void setup() {
  int pin = 12;
  pinMode(pin,OUTPUT);
  pinMode(14,OUTPUT);
  
  tone(pin,440);
  delay(1000);
  noTone(pin);
  //the tone is emitted correctly
  
  delay(1000);
  
  analogWrite(14,200);  
  delay(1000);
  analogWrite(14,0);
  
  tone(pin,440);
  delay(1000);
  noTone(pin);  
  //no tone is emitted
}

void loop() {
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions