Skip to content

PWM analogWrite doesn't work when pinMode is called more than once #8106

Closed
@lvlerber

Description

@lvlerber

Board

esp32 dev module

Device Description

devkit

Hardware Configuration

no

Version

v2.0.6

IDE Name

platformio

Operating System

w10

Flash frequency

40

PSRAM enabled

yes

Upload speed

115200

Description

pinMode(15,OUTPUT);
analogWrite(15,255);
pinMode(15,OUTPUT);
analogWrite(15,128);

With this code I expect the second analogWrite to generate a 50% value on pin 15.
However, the second pinMode instruction will set the value of the pin to 0 and every analogWrite after that will not work.
DigitalWrite will work.

Sketch

#include <Arduino.h>

void setup() {
  // put your setup code here, to run once:
  pinMode(15,OUTPUT);
  analogWrite(15,255);
  delay(5000);
    pinMode(15,OUTPUT);
      delay(5000);
  analogWrite(15,255);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(100);
}

Debug Message

na

Other Steps to Reproduce

na

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions