Python How to run multiple functions simultaneously Question

Asked 2 years ago, Updated 2 years ago, 56 views

The code below states that the two functions are executed sequentially. How do I get two functions to run at the same time? Please.

import OPi.GPIO as GPIO
import time
import subprocess
import atexit

def alarm_call():
    i = 1
    while (i <= 1):
        GPIO.output(alarm_pin, True)
        time.sleep(30)
        GPIO.output(alarm_pin, False)
        time.sleep(0.5)
        i += 1
def led_call():
    i = 1
    while (i <= 30):
        GPIO.output(led, True)
        time.sleep(0.5)
        GPIO.output(led, False)
        time.sleep(0.5)
        i += 1

input_pin = 18
alarm_pin = 9
led = 8

GPIO.setmode(GPIO.BCM)
GPIO.setup(input_pin, GPIO.IN)
GPIO.setup(alarm_pin, GPIO.OUT)
GPIO.setup(led, GPIO.OUT)
GPIO.setwarnings(False)

while True:
    if not GPIO.input(input_pin):
        alarm_call()
        led_call()
    continue
    ```

python orangepi raspberry-pi

2022-09-21 15:25

1 Answers

Self-answer

I solved it. It is sunken with multiprocessing module.


2022-09-21 15:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.