60 lines
1.1 KiB
Python
60 lines
1.1 KiB
Python
|
#!/bin/python3
|
||
|
|
||
|
# Script de test pour le projet de slider de CoCuir
|
||
|
# 3 boutons dont 2 avec des neopixel intégrés. Le 3e servira de bouton power
|
||
|
|
||
|
from time import sleep
|
||
|
import board
|
||
|
import digitalio
|
||
|
import neopixel
|
||
|
|
||
|
# Pinout
|
||
|
NPXL_PIN = board.D18
|
||
|
|
||
|
BUTT_LFT = board.D9
|
||
|
BUTT_RGT = board.D11
|
||
|
BUTT_PWR = board.D10
|
||
|
|
||
|
#Colors
|
||
|
BLUE = (0,0,255)
|
||
|
GREEN = (0,255,0)
|
||
|
RED = (255,0,0)
|
||
|
WHITE = (200,200,200)
|
||
|
BLACK = (0,0,0)
|
||
|
|
||
|
pixels = neopixel.NeoPixel(NPXL_PIN, 2, auto_write=False)
|
||
|
pixels.fill(BLUE)
|
||
|
pixels.show()
|
||
|
|
||
|
button_left = digitalio.DigitalInOut(BUTT_LFT)
|
||
|
button_right = digitalio.DigitalInOut(BUTT_RGT)
|
||
|
button_power = digitalio.DigitalInOut(BUTT_PWR)
|
||
|
|
||
|
buttons = [button_left, button_right, button_power]
|
||
|
|
||
|
for b in buttons:
|
||
|
b.direction = digitalio.Direction.INPUT
|
||
|
b.pull = digitalio.Pull.UP
|
||
|
|
||
|
pixels
|
||
|
|
||
|
while True:
|
||
|
print("{} | {} | {}".format(button_left.value, button_right.value, button_power.value))
|
||
|
if button_left.value :
|
||
|
pixels[0] = GREEN
|
||
|
else:
|
||
|
pixels[0] = WHITE
|
||
|
|
||
|
if button_right.value:
|
||
|
pixels[1] = BLUE
|
||
|
else:
|
||
|
pixels[1] = WHITE
|
||
|
|
||
|
if not button_power.value:
|
||
|
pixels.fill(RED)
|
||
|
|
||
|
pixels.show()
|
||
|
|
||
|
sleep(0.1)
|
||
|
|