Joy-it RB-P-XPLR-SET handleiding
Handleiding
Je bekijkt pagina 30 van 37

30
from machine import Pin
import utime
import neopixel
# Neopixel setup
NUM_LEDS = 4
PIXEL_PIN = 1
np = neopixel.NeoPixel(Pin(PIXEL_PIN), NUM_LEDS)
# Rotate encoder setup
PIN_CLK = Pin(16, Pin.IN, Pin.PULL_UP)
PIN_DT = Pin(17, Pin.IN, Pin.PULL_UP)
BUTTON_PIN = Pin(15, Pin.IN, Pin.PULL_UP)
# Global variables
counter = 0
PIN_CLK_LAST = PIN_CLK.value()
delayTime = 0.001
debounce_time_encoder = 0
debounce_time_button = 0
# Initialize colors
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255)] # Rot, Grün,
Blau, Weiß
color_index = 0
# Initialize brightness
brightness_levels = [0.2, 0.4, 0.6, 0.8, 1.0]
brightness_index = 0
def update_leds(color, brightness):
dimmed_color = tuple([int(c * brightness) for c in color])
for i in range(NUM_LEDS):
np[i] = dimmed_color
np.write()
def rotaryFunction(null):
global counter, brightness_index, debounce_time_encoder
PIN_CLK_CURRENT = PIN_CLK.value()
if PIN_CLK_CURRENT != PIN_CLK_LAST and (utime.ticks_ms() - debounce_time_
encoder) > 300:
if PIN_DT.value() != PIN_CLK_CURRENT:
brightness_index = (brightness_index + 1) % len(brightness_levels)
else:
brightness_index = (brightness_index - 1) % len(brightness_levels)
update_leds(colors[color_index], brightness_levels[brightness_index])
debounce_time_encoder = utime.ticks_ms()
SUMMARY: We use the rotary encoder to control the color and brightness of our four LEDs. Turning the encoder changes the brightness, while pressing the
encoder adjusts the color of the LEDs.
Initialization of the LEDs and the
rotary encoder
Function for the rotary encoder
Bekijk gratis de handleiding van Joy-it RB-P-XPLR-SET, stel vragen en lees de antwoorden op veelvoorkomende problemen, of gebruik onze assistent om sneller informatie in de handleiding te vinden of uitleg te krijgen over specifieke functies.
Productinformatie
Merk | Joy-it |
Model | RB-P-XPLR-SET |
Categorie | Niet gecategoriseerd |
Taal | Nederlands |
Grootte | 21690 MB |