multiple infinite loops running the same time
Posted: Thu Mar 15, 2018 5:52 am
Hello,
I have a raspi project in which I have to create a function to let a LED blink with different parameters.
Here´s the code.
This works as far. But now I have to call this function again with different parameters so that 2 LEDs can blink
I have tried it like this:
But it doesn´t work because with the first blink call the code enters a infinite loop.
Is there a way to start the second infinite loop, so both LEDs can blink?
Thank you.
I have a raspi project in which I have to create a function to let a LED blink with different parameters.
Here´s the code.
Code: Select all
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
from threading import Thread
GPIO.setmode(GPIO.BOARD)
def blink(port, hz):
""" function let´s blink LEDs in variable speed and ports"""
GPIO.setup(port, GPIO.OUT)
while True:
GPIO.output(port, GPIO.HIGH)
time.sleep(0.5/hz)
GPIO.output(port, GPIO.LOW)
time.sleep(0.5/hz)
blink(16, 5)
I have tried it like this:
Code: Select all
...
blink(16, 5)
blink(15, 10)
Is there a way to start the second infinite loop, so both LEDs can blink?
Thank you.