티스토리 뷰
1. sudo nano pishutbtn.py
----------------------------------------------------------------------
#!/usr/bin/python
# shutdown/reboot(/power on) Raspberry Pi with pushbutton
import RPi.GPIO as GPIO
from subprocess import call
from datetime import datetime
import time
# pushbutton connected to this GPIO pin, using pin 5 also has the benefit of
# waking / powering up Raspberry Pi when button is pressed
shutdownPin = 5
# if button pressed for at least this long then shut down. if less then reboot.
shutdownMinSeconds = 3
# button debounce time in seconds
debounceSeconds = 0.01
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(shutdownPin, GPIO.IN)
buttonPressedTime = None
def buttonStateChanged(pin):
global buttonPressedTime
if not (GPIO.input(pin)):
# button is down
if buttonPressedTime is None:
buttonPressedTime = datetime.now()
else:
# button is up
if buttonPressedTime is not None:
elapsed = (datetime.now() - buttonPressedTime).total_seconds()
buttonPressedTime = None
if elapsed >= shutdownMinSeconds:
# button pressed for more than specified time, shutdown
call(['shutdown', '-h', 'now'], shell=False)
elif elapsed >= debounceSeconds:
# button pressed for a shorter time, reboot
call(['shutdown', '-r', 'now'], shell=False)
# subscribe to button presses
GPIO.add_event_detect(shutdownPin, GPIO.BOTH, callback=buttonStateChanged)
while True:
# sleep to reduce unnecessary CPU usage
time.sleep(5)
-----------------------------------------------------------------------
2. sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
@/usr/bin/python3 /home/pi/pishutbtn.py
3. reboot now
출처: GitHub - gilyes/pi-shutdown: Shutdown/reboot(/power on) Raspberry Pi with pushbutton
'ETC' 카테고리의 다른 글
Ubuntu apt-get update 오류 fatch to fail (125) | 2022.05.09 |
---|---|
FileZilla Entry '' has empty native path and no mount nodes: this should never happen. (0) | 2022.01.27 |
Mono .Net Core Https Error: TrustFailure (Authentication failed, see inner exception.) (1) | 2021.12.03 |
라즈베리파이 공식 7인치 백라이트 조절 (124) | 2021.12.02 |
Linux SSH 개인키로 다른 PC에서 접속하기 (2) | 2021.11.18 |
- Total
- Today
- Yesterday
- c# Encrypt / Decrypt
- Entry '' has empty native path
- 연산자 뒤에 피연산자가 없습니다.
- 서버 수준의 URN 필터
- Xamarin Firebase Phone User Add
- WPF Excel Export Microsoft.Office.Interop 성능향상(열 기준으로 복사)
- Xamarin.Ios Firebase Phone SMS OTP Send
- ClickOnce 인증서 인증기간 변경
- Microcharts
- WPF Datagrid Cell Value Change
- Label Text LineBreak in Xaml
- Embeded 한글Font적용
- Xamarin.Ios Firebase Phone Auth
- GetCellContent CheckBox Value
- WPF Textbox
- Linux SSH Multi Computer Join
- C# LINQ Left join
- Xamarin SMS OTP Send
- FileStream Add Byte
- Xamarin.Ios Firebase Phone User Add
- Windows IIS FTP 디렉토리 목록 오류
- SkiaSharp
- WPF Scrollviewer in ScrollViwer
- Xamarin.Forms
- Xamarin reCAPTCHA
- ssl_client_socket_impl.cc
- Xamarin Firebase Phone Auth
- 암호 마스터키
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |