2016-09-14 17 views
0

プロジェクトでは、私はレゴモーターを動かすためにRasterberry Pi(dexter industries modified raspbianを実行)とBrick Piを使いました。私はPythonでプログラムを荒らしました。それは素晴らしいことですが、圧力センサーが押されていないと、プログラム全体を繰り返し実行する必要があります。私はTrueの間にsensorValue()関数(圧力センサーが押されているかどうかを検出する)を呼び出してみました。しかし、かつて私はそのことが奇妙になった。それは無期限に繰り返し続けるだろうし、センサを押しても、繰り返し0は1になるだろうが、実行するために必要な次の関数を呼び出さないだろう。pythonプログラムを完全に再起動する方法

実際には何かを書くために実際にはPythonを使用しています。私は大規模な初心者ですので、どんな助けも大歓迎です。

おかげで再び

from BrickPi import * 

BrickPiSetup() 
BrickPi.MotorEnable[PORT_A] = 1 
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_TOUCH 

BrickPiSetupSensors() 

def sensorValue(): 
    result = BrickPiUpdateValues() 
    if not result : 
     print BrickPi.Sensor[PORT_4] 
    time.sleep(.01) 
    if BrickPi.Sensor[PORT_4] == 0: 

def programBody(): 

    print ("program rest/pause") 
    BrickPi.MotorSpeed[PORT_A] = 0 
    BrickPiUpdateValues() 
    time.sleep(3) 

    print ("reminder/alarm = 200 value") 
    BrickPi.MotorSpeed[PORT_A] = 200 
    ot = time.time() 
    while(time.time() - ot <3): 
     BrickPiUpdateValues() 
     time.sleep(.01) 

    print ("reminder/alarm = 125 value") 
    BrickPi.MotorSpeed[PORT_A] = 125 
    ot = time.time() 
    while(time.time() - ot <3): 
     BrickPiUpdateValues() 
     time.sleep(.01) 

sensorValue() #I would put while True: here but... 

if BrickPi.Sensor[PORT_4]: 
    print "program successfully initiatied" 
    programBody() 
+0

はあなたが行うことができませんでしたしてみてくださいそして走ったが正常状態のISN」の場合、それはその後、0に設定してある場合tを満たしてから1に戻します。 – thesonyman101

+0

@ thesonyman101本当に申し訳ありませんが、私はこれで全部の騒ぎです。実際のPythonは一度もやっていません。ありがとう –

+0

私は本当に素早く何かを作った – thesonyman101

答えて

1

は、x == 1つの実行プログラム中にこの

import BrickPi,time 

BrickPiSetup() 
BrickPi.MotorEnable[PORT_A] = 1 
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_TOUCH 

BrickPiSetupSensors() 

z = 0 
def mainprogram(): 
    print ("running") 
    while x == 1: 
     z = z + 1 
     print ("the plate has been pressed for %s seconds" % z) 
     time.sleep(1) 

while True: 
    time.sleep(.1) 
    if BrickPi.Sensor[PORT_4]: 
     print "program successfully initiatied" 
     mainprogram() 
関連する問題