← index #16603PR #16607
Duplicate · high · value 3.529
QUERY · ISSUE

Pin toggle function does not exist in ESP32.

openby 0wwafaopened 2025-01-17updated 2025-01-25
enhancementport-esp32

Port, board and/or hardware

esp32

MicroPython version

MicroPython v1.24.1 on 2024-11-29; Generic ESP32 module with ESP32

Reproduction

from machine import Pin
p=Pin(2, Pin.OUT)
p.toggle()

Expected behaviour

Toggling the pin :D

Observed behaviour

the toggle function is not implemented.

So I do:
p.value(not p.value())

But from the docs I thought it was implemented.

It would be nice to have it, for code clarity but also for speed.

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

machine.Pin: Implement Pin.toggle() for three ports.

mergedby robert-hhopened 2025-01-18updated 2025-02-28
port-esp8266port-esp32port-cc3200

Summary

The ESP32, ESP8266 and CC3200 ports did not provide the method Pin.toggle(). This PR adds it.

Testing

Tested with:

  • ESP32
  • ESP32C3
  • ESP32C6
  • ESP32S2
  • ESP32S3
  • ESP8266
  • WiPY 1 (CC3200)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied