19/12/2019, 14:45
Salve, come mai mi dice che i led o meglio il pin è già stato usato ? e non posso usare il solito led per fare on , off, blink, fade.
vi allego codice:
Grazie mille.
vi allego codice:
Codice:
#!/usr/bin/env python3
from gpiozero import *
from time import sleep
led = LED(18)
button = Button(21)
def main():
cmd = input("on, off , blink , button: ")
if cmd == 'on':
led.on()
main()
elif cmd == 'off':
led.off()
main()
elif cmd == 'blink':
try:
while True:
led.on()
sleep(1)
led.off()
sleep(1)
except KeyboardInterrupt:
led.off()
sleep(1)
main()
elif cmd == 'button':
try:
while True:
if button.is_pressed:
led.on()
else:
led.off()
except KeyboardInterrupt:
led.off()
sleep(0.5)
main()
elif cmd == 'pwm':
led_pwm = PWMLED(18)
try:
while True:
led_pwm.value = 0
sleep(1)
led_pwm.value = 0.5
sleep(1)
led_pwm.value = 1
sleep(1)
led_pwm.value = 0
sleep(1)
led_pwm.value = 0.5
sleep(1)
led_pwm.value = 1
sleep(1)
except KeyboardInterrupt:
led.off()
sleep(0.5)
main()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
led.off()
Grazie mille.