Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 221

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

Für Python-Sprachbenutzer
Schritt 2: Gehen Sie zum Ordner der Kode.
cd
/home/pi/davinci-kit-for-raspberry-pi/python/
Schritt 3: Führen Sie die ausführbare Datei aus.
sudo python3 2.2.1_Photoresistor.py
Wenn die Kode ausgeführt wird, variiert die Helligkeit der LED in Abhängigkeit von der Lichtintensität, die der
Fotowiderstand erfasst.
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
ADC0834
import
time
LedPin
=
22
def
setup():
global
led_val
# 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)
GPIO.setup(LedPin, GPIO.OUT, initial=GPIO.HIGH)
ADC0834.setup()
# Set led as pwm channel and frequece to 2KHz
led_val
=
GPIO.PWM(LedPin, 2000)
# Set all begin with value 0
led_val.start(0)
def
destroy():
# Stop all pwm channel
led_val.stop()
# Release resource
GPIO.cleanup()
def
loop():
while
True:
analogVal
=
print
('analog value = %d'
led_val.ChangeDutyCycle(analogVal
time.sleep(0.2)
if
__name__
==
'__main__':
setup()
try:
loop()
except
KeyboardInterrupt:
be executed.
1.8. 2 Eingabe
GPIO
ADC0834.getResult()
%
analogVal)
# When 'Ctrl+C' is pressed, the program destroy() will
100/255)
*
SunFounder Da Vinci Kit
(Fortsetzung auf der nächsten Seite)
217

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis