我运行一个Rpi W(Rbian Jessie),就像一个游戏中时光倒流倒计时系统,下面的脚本允许每分钟拍照并在按钮关闭时睡觉。程序每隔5秒检查一次按钮。
# This Python file uses the following encoding: utf-8
from time import sleep
from picamera import PiCamera
import os
import time
import RPi.GPIO as GPIO
import picamera
import datetime as dt
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
os.system('sudo python /home/pi/log.py')
check = GPIO.input(17)
while check == 0: #si l'état initial du bouton = 0
check = GPIO.input(17)
print(check)
sleep(5)
while check == 1: #si l'état initial = 1
with picamera.PiCamera() as camera:
camera.resolution = (1280, 720)
sleep(1)
t1 = dt.datetime.now().strftime('-%d_%m_%Y-%H_%M_%S')
t2 = 'IMG'+ t1
camera.capture('/home/pi/Pictures/%s.jpg' % t2)
print('Captured %s' % t2)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(5)
check = GPIO.input(17)
print(check)
sleep(4)
check = GPIO.input(17)
print(check)
while check == 0: #si l'état initial du bouton = 0
check = GPIO.input(17)
print(check)
sleep(5)
我确定剧本是令人厌恶的......
但我想做的是:调用另一个名为log.py的脚本(监视T°和时间/分钟)。但是,主脚本在行之后停止:#os.system('sudo python /home/pi/log.py')...如果没有这行,脚本运行正常。
有人可以了解一些事情吗?
答案 0 :(得分:0)
使用:
os.system('sudo python /home/pi/log.py &')
& 分叉了这个过程。