Learn electronics, coding, and projects — step by step.

003 – ESP32 MicroPython: General Purpose Input Output | GPIO Pins

George Bantique September 9, 2020 1 Comment

Video Demonstration:

If you like this tutorial and you find it useful, please Share it to your friends. Please consider also supporting me by Subscribing. Click this to Subscribe to TechToTinker Youtube channel.

Source Code:

Example 1:

import machine
import time
led = machine.Pin(2, machine.Pin.OUT)
counter = 0
while (counter < 5):
    led.on()
    time.sleep(0.5)
    led.off()
    time.sleep(0.5)
    counter += 1
print('Blinking LED is complete')

Example 2:

import machine
import time
led = machine.Pin(2, machine.Pin.OUT)
def blink_led_ntimes(num, t_on, t_off, msg):
    counter = 0
    while (counter < num):
        led.on()
        time.sleep(t_on)
        led.off()
        time.sleep(t_off)
        counter += 1
    print(msg)

Example 3:

import machine
led = machine.Pin(2, machine.Pin.OUT)
sw = machine.Pin(0, machine.Pin.IN)
while True:
    if (sw.value() == 0):
        led.on()
    else:
        led.off()

One Comment

  1. Unknown says:

    Thank You very mutch George Bantique!

Leave a Reply

Required fields are marked *






Related Articles: