Joy-IT Go TRONIC Manuel D'utilisation page 6

Table des Matières

Publicité

# Regarde si un bouton est poussé
rowVal = -1
for i in range(len(self.ROW)):
tmpRead = GPIO.input(self.ROW[i])
if tmpRead == 0:
rowVal = i
if rowVal <0 or rowVal >3:
self.exit()
return
for j in range(len(self.COLUMN)):
GPIO.setup(self.ROW[rowVal], GPIO.OUT)
GPIO.output(self.ROW[rowVal], GPIO.HIGH)
colVal = -1
for j in range(len(self.COLUMN)):
if colVal <0 or colVal >3:
self.exit()
return self.KEYPAD[rowVal][colVal]
def exit(self):
# Retourne le nom du bouton pressé
for i in range(len(self.ROW)):
for j in range(len(self.COLUMN)):
if __name__ == '__main__':
# Initialisation du clavier
kp = keypad()
print '--- Clavier prêt ---'
# Boucle principale
while True:
digit = None
while digit == None:
# Affiche le nom de la touche enfoncée
print digit
time.sleep(0.5)
Sauvegardez le fichier (Ctrl+O et Enter) et quittez le fichier (Ctrl+X).
Vous pouvez exécuter le programme :
sudo python matriceBP.py
Ctrl+C pour arrêter le programme
GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
tmpRead = GPIO.input(self.COLUMN[j])
if tmpRead == 1:
colVal=j
self.exit()
return
# Retourne la position du bouton pressé
GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_UP)
digit = kp.getKey()
Page 6 de 7

Publicité

Table des Matières
loading

Table des Matières