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

35
from machine import Pin
import utime
# Initialize the LED pins
red_led = Pin(18, Pin.OUT)
green_led = Pin(17, Pin.OUT)
blue_led = Pin(16, Pin.OUT)
# Initialize the button pins
button_red = Pin(15, Pin.IN, Pin.PULL_UP)
button_green = Pin(10, Pin.IN, Pin.PULL_UP)
button_blue = Pin(11, Pin.IN, Pin.PULL_UP)
# Save states of the LEDs
red_state = False
green_state = False
blue_state = False
def toggle_led(led, state):
led.value(state)
while True:
# Check the status of the red button
if button_red.value() == 0:
red_state = not red_state
toggle_led(red_led, red_state)
utime.sleep(0.2) # Entprellung
# Check the status of the green button
if button_green.value() == 0:
green_state = not green_state
toggle_led(green_led, green_state)
utime.sleep(0.2) # Entprellung
# Check the status of the blue button
if button_blue.value() == 0:
blue_state = not blue_state
toggle_led(blue_led, blue_state)
utime.sleep(0.2) # Debouncing
SUMMARY: The three color channels of the RGB LED (red, green & blue) are switched on and o using the buttons (le, top & right).
Initialization of the LED and the
buttons
Testing the buttons and controlling
the LED
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 |