Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 249

Für den raspberry pi 4 modell b, 3 modell a +, 3 modell b +, 3 modell b, 2 modell b, 1 modell b +, 1 modell a +, zero w and zero
Inhaltsverzeichnis

Werbung

# Define a function to set up colors
def
setColor(color):
# configures the three LEDs' luminance with the inputted color value .
# Devide colors from 'color' veriable
R_val
=
(color
G_val
=
(color
B_val
=
(color
# Map color value from 0~255 to 0~100
R_val
=
MAP(R_val, 0, 255, 0, 100)
G_val
=
MAP(G_val, 0, 255, 0, 100)
B_val
=
MAP(B_val, 0, 255, 0, 100)
#Assign the mapped duty cycle value to the corresponding PWM channel to change
the luminance.
p_R.ChangeDutyCycle(R_val)
p_G.ChangeDutyCycle(G_val)
p_B.ChangeDutyCycle(B_val)
#print ("color_msg: R_val = %s, G_val = %s,
def
loop():
while
True:
pir_val
=
GPIO.input(pirPin)
if
pir_val==GPIO.HIGH:
setColor(0xFFFF00)
else
:
setColor(0x0000FF)
def
destroy():
p_R.stop()
p_G.stop()
p_B.stop()
GPIO.cleanup()
if
__name__
==
'__main__':
setup()
try:
loop()
except
KeyboardInterrupt:
destroy() will be
destroy()
Code Erklärung
rgbPins
=
{'Red':18, 'Green':27, 'Blue':22}
def
setup():
global
p_R, p_G, p_B
GPIO.setmode(GPIO.BCM)
# ......
for
i
in
rgbPins:
GPIO.setup(rgbPins[i], GPIO.OUT, initial=GPIO.HIGH)
p_R
=
GPIO.PWM(rgbPins['Red'], 2000)
p_G
=
GPIO.PWM(rgbPins['Green'], 2000)
p_B
=
GPIO.PWM(rgbPins['Blue'], 2000)
p_R.start(0)
p_G.start(0)
1.8. 2 Eingabe
&
0xFF0000)
>>
16
&
0x00FF00)
>>
8
&
0x0000FF)
>>
0
# Program start from here
# When 'Ctrl+C' is pressed, the child program
executed.
B_val = %s"%(R_val, G_val, B_val))
# Release resource
SunFounder Da Vinci Kit
(Fortsetzung der vorherigen Seite)
(Fortsetzung auf der nächsten Seite)
245

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis