Skip to content

Add .toggle() function on ESP32 Port #8789

Description

@uPesy
  • ESP32 Port

  • The function Pin.toggle() in RP2040 port is not implemented in the ESP32 Port. This function enables to reverse the logic state of a Pin.
    image

Activity

  1. added
    enhancementFeature requests, new feature implementations
    on Jun 20, 2022
  2. peterhinch commented on Jun 20, 2022

    @peterhinch
    Contributor

    The machine.Pin class does not support .toggle on any platform. Just write

    p = Pin(number, Pin.OUT)
    p(not p())
  3. uPesy commented on Jun 20, 2022

    @uPesy
    Author

    There is a toggle function on Raspberry Pi Pico port. This code works great on it :

    from machine import Pin
    import time
    
    pin_led = Pin(25, mode=Pin.OUT)
    
    while True:
        pin_led.toggle()
        time.sleep_ms(250)
    

    But not on ESP32 port

  4. peterhinch commented on Jun 21, 2022

    @peterhinch
    Contributor

    Interesting. It doesn't appear in the docs.

  5. fconrotte commented on Sep 18, 2022

    @fconrotte

    Hello !

    I teach kids about microPython on the cansat project http://cansat.lu/

    I tell them to look at the doc to find the meaning of functions but the first one they use PIN.toggle() is indeed not documented :)

    Where can I file a bug report for this ?

  6. robert-hh commented on Sep 18, 2022

    @robert-hh
    Contributor

    Where can I file a bug report for this ?

    Here, under the issues tab.

  7. millosolomillo commented on Oct 17, 2022

    @millosolomillo

    Hello !

    I teach kids about microPython on the cansat project http://cansat.lu/

    I tell them to look at the doc to find the meaning of functions but the first one they use PIN.toggle() is indeed not documented :)

    Where can I file a bug report for this ?

    Issue opened at #9652

  8. agatti commented on Mar 21, 2026

    @agatti
    Contributor

    This was added in #16607, available since v1.25.0. Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementationsport-esp32

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions