Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

Python • Re: Creating Separate PWM Objects in Multiple Threads

$
0
0
dBerriff,

Unfortunately, that doesn't work. Since there's only a single PWM object created, the next thread in line can't access it until the current thread is done using it (which makes sense). However, the threads then just act as sequential code, which defeats the purpose of threading.

Unless I'm implementing incorrecting.

I just added the following near the top of the file:

Code:

lock = threading.Lock()
and the following inside the power look:

Code:

def power(device, level, duration):        with lock:                output = GPIO.PWM(myOuts[device], 1000)                output.start(level)                sleep(duration)                output.stop()
I'm thinking now that the solution is to create a list of PWM objects and iterate through them as needed (appending and popping as I go). I'm just a little confused on how to implement that properly.

-Joe

Statistics: Posted by joebro391 — Thu Mar 27, 2025 1:44 pm



Viewing all articles
Browse latest Browse all 8026

Trending Articles