Hello ,
I have a small project that monitor voltage using ina3221
when I run it in main infite loop it's work as it should - no problem there.
I want to be abele to run my "Check Voltage Function" while I send a commnd to device , so I will be able to check the used voltage
this is what I have :
so I will know how much voltage\current the device is using to play to file
********
I found this
[inline=https://stackoverflow.com/questions/7168508/background-function-in-python][/inline]
and try to add this :
Thanks ,
I have a small project that monitor voltage using ina3221
when I run it in main infite loop it's work as it should - no problem there.
I want to be abele to run my "Check Voltage Function" while I send a commnd to device , so I will be able to check the used voltage
this is what I have :
import sleep import date import SDL_Pi_INA3221 import os import sys import random TestSound = ["/Music/latvia.mp3","/Music/russia.mp3","/Music/France.mp3"] CH3 = 3 def Check_Voltage(): Voltage = ina3221.getBusVoltage_V(CH3) Current = ina3221.getCurrent_mA(CH3) print("Volume AMP Voltage : " + str(Voltage)) print("Volume AMP Current : " + str (Current)) while 1: i = (i + 1) date = datetime.now().strftime('%d-%m-%y %H-%M-%S') print(i, date) select = input('Press 1 to send random MP3 \n\r') if select == '1': os.system("mpg123 -o alsa:hw:2,0 " + random.choice(TestSound)) Check_Voltage() else: print ('no sound will play , wait for next time! ') sleep(5)I want after I press "1" to run the function it will also send me the "play command "
so I will know how much voltage\current the device is using to play to file
********
I found this
[inline=https://stackoverflow.com/questions/7168508/background-function-in-python][/inline]
and try to add this :
thread_function = threading.Thread(target=Check_Voltage) thread_function.start() os.system("mpg123 -o alsa:hw:2,0 " + random.choice(TestSound))but it only run me the "Check_Voltage" 1 time before running the "play" command
Thanks ,