Created
December 16, 2023 16:46
-
-
Save indriApollo/4b1327138334947fe04e79ca2fa58003 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import time | |
def export_gpio(num): | |
with open('/sys/class/gpio/export', 'w') as e: | |
e.write(str(num)) | |
def unexport_gpio(num): | |
with open('/sys/class/gpio/unexport', 'w') as e: | |
e.write(str(num)) | |
def gpio_dir(num): | |
return f'/sys/class/gpio/gpio{num}' | |
def set_direction_out(num): | |
with open(f'{gpio_dir(num)}/direction', 'w') as e: | |
e.write('out') | |
def init_gpio(num): | |
export_gpio(num) | |
set_direction_out(num) | |
def deinit_gpio(num): | |
set_off(num) | |
unexport_gpio(num) | |
def set_on(num): | |
with open(f'{gpio_dir(num)}/value', 'w') as e: | |
e.write('1') | |
def set_off(num): | |
with open(f'{gpio_dir(num)}/value', 'w') as e: | |
e.write('0') | |
def init_all(nums): | |
for n in nums: | |
init_gpio(n) | |
def deinit_all(nums): | |
for n in nums: | |
deinit_gpio(n) | |
leds = [ 17, 18, 27, 22, 23, 24, 14, 4 ] | |
init_all(leds) | |
for n in leds: | |
set_on(n) | |
time.sleep(0.5) | |
set_off(n) | |
deinit_all(leds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With MAD effects !