Python:While循环中导入函数的奇怪问题

雨天

所以我有一个难题。让我们从我的代码的相关片段开始。

from RECORD import recordSystem

recTime = 30 #Amount of time(seconds) I want to record the audio input

while True: #I want to keep this active while system is running

#Standard raspberry Pi input sensors. 
if(GPIO.input(LedPin4) == GPIO.LOW and GPIO.input(LedPin5) == GPIO.HIGH:  
  recordSystem(recTime) #when condition is met run the code. 

因此,我尝试运行的功能来自我编写的另一个脚本。而且有效。它记录模拟音频并在我的项目文件夹中创建一个.wav文件。这段代码的问题在于,它昨天可以正常工作,而现在却找不到。没有任何改变或感动。它只是不想工作。发生的情况是循环开始,并且当满足条件时,该功能将正确启动,并且我在编译器中收到“录制”通知。但是它永远不会停止录制。当我在循环外执行以下操作时:

recordSystem(recTime)

该功能正常运行,没有任何问题。因此,它必须在循环内调用该函数。但是,一段时间以来它一直没有任何问题。谁能给我最好的客人,说明可能会发生什么?非常感激!

布罗斯塔

break在您之后添加一条语句recordSystem(recTime)应该可以解决问题!我还修复了缩进,并(从代码中删除了其他内容

from RECORD import recordSystem

recTime = 30 #Amount of time(seconds) I want to record the audio input

while True: #I want to keep this active while system is running

    #Standard raspberry Pi input sensors. 
    if GPIO.input(LedPin4) == GPIO.LOW and GPIO.input(LedPin5) == GPIO.HIGH:  
        recordSystem(recTime) #when condition is met run the code. 
        break

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章