Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 49

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

Bemerkung: Sie können den folgenden Code Ändern/Zurücksetzen/ Kopieren/Ausführen/Stoppen. Zuvor müssen
Sie jedoch zu einem Quellcodepfad wie davinci-kit-for-raspberry-pi\\python gehen.
import
RPi.GPIO
as
import
time
# Set up a color table in Hexadecimal
COLOR
=
[0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]
# Set pins' channels with dictionary
pins
=
{'Red':17, 'Green':18, 'Blue':27}
def
setup():
global
p_R, p_G, p_B
# Set the GPIO modes to BCM Numbering
GPIO.setmode(GPIO.BCM)
# Set all LedPin's mode to output and initial level to High(3.3v)
for
i
in
pins:
GPIO.setup(pins[i], GPIO.OUT, initial=GPIO.HIGH)
# Set all led as pwm channel and frequece to 2KHz
p_R
=
GPIO.PWM(pins['Red'], 2000)
p_G
=
GPIO.PWM(pins['Green'], 2000)
p_B
=
GPIO.PWM(pins['Blue'], 2000)
# Set all begin with value 0
p_R.start(0)
p_G.start(0)
p_B.start(0)
# Define a MAP function for mapping values.
def
MAP(x, in_min, in_max, out_min, out_max):
return
(x
-
in_min)
# Define a function to set up colors
# input color should be Hexadecimal with
# red value, blue value, green value.
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
# these three lines are used for analyzing the col variables
# assign the first two values of the hexadecimal to R, the middle two assigned to G
# assign the last two values to B, please refer to the shift operation of the
hexadecimal for details.
# 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)
# Change the colors
p_R.ChangeDutyCycle(R_val)
# Assign the mapped duty cycle value to the corresponding PWM channel to change
the luminance.
1.7. 1 Ausgabe
GPIO
(out_max
-
out_min)
*
&
0xFF0000)
>>
16
&
0x00FF00)
>>
8
&
0x0000FF)
>>
0
Like from 0~255 to 0~100
/
(in_max
-
in_min)
SunFounder Da Vinci Kit
+
out_min
(Fortsetzung auf der nächsten Seite)
45

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis