Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 170

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

SunFounder Da Vinci Kit
Code
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 #17 as slide switch pin, #22 as led1 pin, #27 as led2 pin
slidePin
=
17
led1Pin
=
22
led2Pin
=
27
# Define a setup function for some setup
def
setup():
# Set the GPIO modes to BCM Numbering
GPIO.setmode(GPIO.BCM)
# Set slidePin input
# Set ledPin output,
# and initial level to High(3.3v)
GPIO.setup(slidePin, GPIO.IN)
GPIO.setup(led1Pin, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(led2Pin, GPIO.OUT, initial=GPIO.HIGH)
# Define a main function for main process
def
main():
while
True:
# slide switch high, led1 on
if
GPIO.input(slidePin)
print
('LED1
GPIO.output(led1Pin, GPIO.LOW)
GPIO.output(led2Pin, GPIO.HIGH)
# slide switch low, led2 on
if
GPIO.input(slidePin)
print
('
GPIO.output(led2Pin, GPIO.LOW)
GPIO.output(led1Pin, GPIO.HIGH)
time.sleep(0.5)
# Define a destroy function for clean up everything after
# the script finished
def
destroy():
# Turn off LED
GPIO.output(led1Pin, GPIO.HIGH)
GPIO.output(led2Pin, GPIO.HIGH)
# Release resource
GPIO.cleanup()
# If run this script directly, do:
if
__name__
==
'__main__':
setup()
try:
main()
# When 'Ctrl+C' is pressed, the program
# destroy() will be
166
GPIO
==
1:
ON')
==
0:
LED2
ON')
executed.
(Fortsetzung auf der nächsten Seite)
Kapitel 1. Über das Da Vinci Kit

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis