Last active
July 15, 2020 12:00
-
-
Save hrchu/a081594fb6f618e1645ae65d049125c7 to your computer and use it in GitHub Desktop.
Blink LED on Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace /sys/class/leds/led0/trigger with /sys/class/leds/led0 while on Raspberry Pi 2 model B | |
def read_trigger() -> str: | |
with open('/sys/class/leds/led0/trigger', 'r') as trigger: | |
return trigger.read() | |
org_trigger = read_trigger() | |
def disable_trigger(): | |
with open('/sys/class/leds/led0/trigger', 'w') as trigger: | |
trigger.write('none') | |
def restore_trigger(): | |
with open('/sys/class/leds/led0/trigger', 'w') as trigger: | |
trigger.write(org_trigger) | |
def led_on(): | |
with open('/sys/class/leds/led0/brightness', 'w') as brightness: | |
brightness.write('255') | |
print('on') | |
def led_off(): | |
with open('/sys/class/leds/led0/brightness', 'w') as brightness: | |
brightness.write('0') | |
print('off') | |
import time | |
def blink(sec: int): | |
disable_trigger() | |
for i in range(sec): | |
led_on() | |
time.sleep(1) | |
led_off() | |
time.sleep(1) | |
if __name__ == '__main__': | |
blink(555555) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment