能。把它写入开机启动项就好了。
import RPi.GPIO as GPIO
import time
import os,sys
import signal
GPIO.setmode(GPIO.BCM)
#define GPIO pin
pin_btn=7
pin_led=17
GPIO.setup(pin_btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin_led, GPIO.OUT, initial=GPIO.LOW)
press_time=0
count_down=10
led_on=1
def cleanup():
'''释放资源,不然下次运行是可能会收到警告
'''
print('clean up')
GPIO.cleanup()
def handleSIGTERM(signum, frame):
#cleanup()
sys.exit()#raise an exception of type SystemExit
def onPress(channel):
global press_time,count_down
print('pressed')
press_time+=1
if press_time >3:
press_time=1
if press_time==1:
GPIO.output(pin_led, 1)
print('system will restart in %s'%(count_down))
elif press_time==2:
print('system will halt in %s'%(count_down))
elif press_time==3:
GPIO.output(pin_led, 0)
能。把它写入开机启动项就好了。
import RPi.GPIO as GPIO
import time
import os,sys
import signal
GPIO.setmode(GPIO.BCM)
#define GPIO pin
pin_btn=7
pin_led=17
GPIO.setup(pin_btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin_led, GPIO.OUT, initial=GPIO.LOW)
press_time=0
count_down=10
led_on=1
def cleanup():
'''释放资源,不然下次运行是可能会收到警告
'''
print('clean up')
GPIO.cleanup()
def handleSIGTERM(signum, frame):
#cleanup()
sys.exit()#raise an exception of type SystemExit
def onPress(channel):
global press_time,count_down
print('pressed')
press_time+=1
if press_time >3:
press_time=1
if press_time==1:
GPIO.output(pin_led, 1)
print('system will restart in %s'%(count_down))
elif press_time==2:
print('system will halt in %s'%(count_down))
elif press_time==3:
GPIO.output(pin_led, 0)
举报