Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 204

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
i, row
for
GPIO.output(row, GPIO.HIGH)
for
j, col
index
if
GPIO.output(row, GPIO.LOW)
return
pressed_keys
setup():
def
global
keypad, last_key_pressed
rowsPins
=
[18,23,24,25]
colsPins
=
[10,22,27,17]
keys
=
["1","2","3","A",
"4","5","6","B",
"7","8","9","C",
" *
","0","#","D"]
keypad
=
Keypad(rowsPins, colsPins, keys)
last_key_pressed
def
loop():
global
keypad, last_key_pressed
pressed_keys
=
if
len(pressed_keys)
print(pressed_keys)
last_key_pressed
time.sleep(0.1)
# Define a destroy function for clean up everything after the script finished
def
destroy():
# Release resource
GPIO.cleanup()
if
__name__
==
'__main__':
try:
setup()
while
True:
loop()
except
KeyboardInterrupt:
will be executed.
destroy()
Code Erklärung
def
setup():
global
keypad, last_key_pressed
rowsPins
=
[18,23,24,25]
colsPins
=
[10,22,27,17]
keys
=
["1","2","3","A",
"4","5","6","B",
"7","8","9","C",
" *
","0","#","D"]
keypad
=
Keypad(rowsPins, colsPins, keys)
last_key_pressed
Deklarieren Sie jede Taste der Matrixtastatur zu den Array- keys[] und definieren Sie die Pins für jede Zeile und Spalte.
200
enumerate(self.rowsPins):
in
in
enumerate(self.colsPins):
=
i
len(self.colsPins)
*
(GPIO.input(col)
==
pressed_keys.append(self.keys[index])
=
[]
keypad.read()
!=
0
and
last_key_pressed
=
pressed_keys
# Program start from here
# When 'Ctrl+C' is pressed, the program destroy()
=
[]
+
j
1):
!=
pressed_keys:
(Fortsetzung der vorherigen 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