Closed
2

ラズパイゼロとgpiozeroでLチカ

from gpiozero import PWMLED
from time import sleep

white = PWMLED(22)
yellow = PWMLED(17)
red = PWMLED(10)
green = PWMLED(11)

while True:
    green.pulse()
    sleep(1)
    red.pulse()
    sleep(1)
    white.pulse()
    sleep(1)
    yellow.pulse()
    sleep(1)

コントローラーを使ったバージョン

from evdev import InputDevice, categorize, ecodes
from gpiozero import PWMLED
from time import sleep

gamepad = InputDevice('/dev/input/event0')

print(gamepad)

red = PWMLED(17)
yellow = PWMLED(22)
blue = PWMLED(10)
white = PWMLED(11)

class Btn:
  A = 305
  B = 304
  X = 307
  Y = 306
  R = 309
  L = 308
  START = 313
  SELECT = 312

#evdev takes care of polling the controller in a loop
for event in gamepad.read_loop():
    if event.type == ecodes.EV_KEY and event.value == 1:
        if event.code == Btn.A:
            print("A")
            yellow.blink(n=1)
        elif event.code == Btn.B:
            print("B")
            red.blink(n=1)
        elif event.code == Btn.X:
            print("X")
            blue.blink(n=1)
        elif event.code == Btn.Y:
            print("Y")
            white.blink(n=1)
        elif event.code == Btn.R:
            print("R")
        elif event.code == Btn.L:
            print("L")
        elif event.code == Btn.START:
            print("START")
        elif event.code == Btn.SELECT:
            print("SELECT")
このスクラップは1ヶ月前にクローズされました
ログインするとコメントできます