mirror of
https://github.com/RGBCube/GDUS
synced 2025-07-28 21:47:45 +00:00
Fix led toggle code
This commit is contained in:
parent
1b15f3798f
commit
04a391db82
1 changed files with 7 additions and 8 deletions
15
rpid/main.py
15
rpid/main.py
|
@ -4,13 +4,12 @@ from fastapi import FastAPI
|
||||||
import RPi.GPIO as gpio
|
import RPi.GPIO as gpio
|
||||||
|
|
||||||
leds = [
|
leds = [
|
||||||
(),
|
[17, True],
|
||||||
(17, True),
|
[18, True],
|
||||||
(18, True),
|
[19, True],
|
||||||
(19, True),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
for led in leds[1::]:
|
for led in leds:
|
||||||
gpio.setmode(gpio.BCM)
|
gpio.setmode(gpio.BCM)
|
||||||
gpio.setup(led[0], gpio.OUT)
|
gpio.setup(led[0], gpio.OUT)
|
||||||
gpio.output(led[0], int(led[1]))
|
gpio.output(led[0], int(led[1]))
|
||||||
|
@ -20,14 +19,14 @@ app = FastAPI()
|
||||||
@app.get("/led/toggle")
|
@app.get("/led/toggle")
|
||||||
async def toggle(number: int) -> str:
|
async def toggle(number: int) -> str:
|
||||||
global leds
|
global leds
|
||||||
led = leds[number]
|
led = leds[number - 1]
|
||||||
leds[number] = (led[0], not led[1])
|
|
||||||
|
|
||||||
gpio.output(led[0], int(led[1]))
|
gpio.output(led[0], int(led[1]))
|
||||||
|
|
||||||
turn_off = leds.copy()
|
turn_off = leds.copy()
|
||||||
turn_off.remove(led)
|
turn_off.remove(led)
|
||||||
turn_off.remove(())
|
|
||||||
|
leds[number - 1][1] = not led[1]
|
||||||
|
|
||||||
# Horrible code, but time is running out and so is
|
# Horrible code, but time is running out and so is
|
||||||
# my motivation for this project.
|
# my motivation for this project.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue