Why my simple LED example is not toggling

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Why my simple LED example is not toggling

Post by nikhiledutech » Mon Mar 26, 2018 5:55 am

Here is my simple example to blink LED, and i guess it was working properly previously but its not working now.
import pyb
from pyb import Pin, delay


#Initalising LED Pins
led1 = pyb.Pin('PE8', Pin.OUT, Pin.PULL_DOWN)

#Blinking lEd
while (True):
led1.low() #Turning LED ON
pyb.delay(5000)
led1.high() #Turning LED OFF

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Why my simple LED example is not toggling

Post by pythoncoder » Mon Mar 26, 2018 6:24 am

Your code needs another delay. As written it turns the LED off but turns it on again so quickly that you'll never see the blink.

Code: Select all

while (True):
    led1.low() #Turning LED ON
    pyb.delay(5000)
    led1.high() #Turning LED OFF
    pyb.delay(5000)
As a general comment it's best to be consistent: use one or the other of import pyb or from pyb import Pin, delay:

Code: Select all

import pyb
#Initalising LED Pins
led1 = pyb.Pin('PE8', pyb.Pin.OUT, pyb.Pin.PULL_DOWN)

#Blinking LED
while (True):
    led1.low()        #Turning LED ON
    pyb.delay(5000)
    led1.high()       #Turning LED OFF
    pyb.delay(5000)
Peter Hinch
Index to my micropython libraries.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Why my simple LED example is not toggling

Post by nikhiledutech » Mon Mar 26, 2018 7:02 am

Also there is some issues with LCD example. I have created this example before 2-3 months. But its not working now. Did any library got updated.

The below code dont give me error, but it dont give me output either.
import uasyncio as asyncio
import utime as time
from alcd import LCD, PINLIST

lcd = LCD(PINLIST, cols = 16)

async def lcd_task():
for secs in range(20, -1, -1):
lcd[0] = 'Edutech Learning'
lcd[1] = "Solution"
await asyncio.sleep(1)


loop = asyncio.get_event_loop()
loop.run_until_complete(lcd_task())

Post Reply