1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
from threading import Thread
import RPi.GPIO as GPIO
import time
import socket
import sys
hote ="192.168.1.21"
port =9000
socket3 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket3.connect((hote, port))
ActiveFunc = 1
GPIO.setmode(GPIO.BCM)
MATRIX = [[308,309,310], #entier envoyé correspondant au pages
[311,311,312],
[255,256,303]]
ROW = [18,23,24]
COL = [22,27,12]
for j in range(3):
GPIO.setup(COL[j], GPIO.OUT)
GPIO.output(COL[j],1)
for i in range(3):
GPIO.setup(ROW[i],GPIO.IN, pull_up_down = GPIO.PUD_UP)
class Worker(Thread):
def run(self):
try:
while(True):
for j in range(3):
GPIO.output(COL[j],0)
for i in range(3):
if GPIO.input(ROW[i]) == 0:
ActiveFunc= '1'
SWnbr=str(MATRIX[i][j])
SWdir='3'
txt=SWnbr+'\r''\n'
print(len(txt))#juste pour info
print(txt)#juste pour info
socket3.send(txt.encode('utf_8'))
while(GPIO.input(ROW[i]) == 0):
time.sleep(1.2) # pause trop longue pour le bon fonctionnement de la boucle de la matrice
pass
GPIO.output(COL[j],1)
except KeyboardInterrupt:
GPIO.cleanup()
return
Worker().start() |
Partager