Raspberry PI [Autorun]

Page 1

การตัง้ ค่าให้ชดุ คําสังเร ่ ิ่ มทํางานอัตโนมัติ 1.สร้างชุดคําสังที ่ ่ต้องการจะรันแบบอัตโนมัติ โดยในที่นี้ใช้ชดุ คําสัง่ LED.py และได้มีการเพิ่มการต่อสวิตช์ไว้ ที่ GPIO 22 (ต่อแบบ Active low) เมื่อมีการกดสวิตช์โปรแกรมก็จะหยุดการทํางาน import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) ledPin=16 swPin=22 GPIO.setup(ledPin,GPIO.OUT) GPIO.setup(swPin,GPIO.IN) print("Strat......")

try: while (GPIO.input(swPin)): GPIO.output(ledPin,0) time.sleep(0.5) #print("Relay=OFF") GPIO.output(ledPin,1) time.sleep(0.5) #print("Relay=ON") finally: GPIO.cleanup()


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.