Standalone LED flash script
This commit is contained in:
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Flash-LED
|
||||||
|
Standalone Python script to flash an LED on GPIO 17 of a Raspberry Pi.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
`python3 flash_led.py`
|
||||||
|
|
||||||
|
Requires `RPi.GPIO` to be installed on the host.
|
||||||
19
flash_led.py
Normal file
19
flash_led.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Use GPIO 17
|
||||||
|
PIN = 17
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(PIN, GPIO.OUT)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print("Flashing LED for 10 seconds...")
|
||||||
|
start_time = time.time()
|
||||||
|
while time.time() - start_time < 5:
|
||||||
|
GPIO.output(PIN, GPIO.HIGH)
|
||||||
|
time.sleep(0.3)
|
||||||
|
GPIO.output(PIN, GPIO.LOW)
|
||||||
|
time.sleep(0.3)
|
||||||
|
finally:
|
||||||
|
GPIO.cleanup()
|
||||||
|
print("Done.")
|
||||||
Reference in New Issue
Block a user