executing a class in the background so another class can still receive inputs #9433
Replies: 2 comments 2 replies
-
This sounds like a case where using You can create independent tasks for each thing that needs to run concurrently. |
Beta Was this translation helpful? Give feedback.
-
Hello and many thanks for your answer, I have tried to adopt uasyncio in my program. For easier reading, I have omitted the previous issue_cmd class and simply made those functions of the main program. So now I only have the class laser_turret which resides in her own file and is the only thing that incorporates uasyncio - you can see the code below. The class can now run by it's own as well, all that is needed is the setup.py and laser_turret_class.py. However, when I try to run it, I get this error:
I am pretty sure I am doing something completely stupid here, but this is the original
and this is, how I adopted it:
the complete output is this:
Ans as said, my class looks like this now:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
Before I start, let me say that I am fairly if not to say completely new to micropython and also only have rather limited knowledge of multithreading or parallel execution in python as well. I have a Raspberry PiCo which shall control a model of the millennium falcon I am building.
The PiCo is supposed to turn on LEDs (like the engine and cockpit lights or hall way lights) and motors (like the radio dish and the laser turrets) as per infrared remote. Turning these elements on and off works perfectly fine - I can turn the lights and motors on and off. My issue is with driving the laser turret servo. This is a rather lengthy "function" that is positioning the servo in a semi random pattern with semi random pauses and a lengthy pause at the end of the cycle - currently in the code the pattern is static, but I will make it semi random in the future.
Now, what I would like to achieve is this: While this lengthy function is running, I would like to still be able to turn on and off other lights or the motor for the radio dish. Unfortunately I have no idea how to achieve this.
My lengthy function is within it's own class executed from within the class that executes all functions as per code received from the IR class - see codes below.
Can someone telll me, how to initialise this class in the background, so that the initial class can continue receiving commands from the remote?
Kind regards,
Christian
My main.py:
local_ISSUE_CMD.py with the two classes executing the functions:
my setup.py that holds all static values and defines the PINs - just for the sake of completeness:
my IR class to retrieve the codes from the remote:
init.py from the original IR receiver code:
Beta Was this translation helpful? Give feedback.
All reactions