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
| #!/usr/bin/env python
import RPi.GPIO as GPIO
import time
listeports=[[7,'GPIO4'],[11,'GPIO17'],[12,'GPIO18'],[13,'GPIO27'],[15,'GPIO22']
,[16,'GPIO23'],[18,'GPIO24'],[22,'GPIO25'],[29,'GPIO5'],[31,'GPIO6']
,[32,'GPIO12'],[33,'GPIO13'],[35,'GPIO19'],[36,'GPIO16'],[37,'GPIO26']
,[38,'GPIO20'],[40,'GPIO21']]
def setup():
GPIO.setmode(GPIO.BOARD)
for ports in listeports:
GPIO.setup(ports[0],GPIO.IN)
def destroy():
GPIO.cleanup()
if __name__ == '__main__':
setup()
print (str(len(listeports)) + " ports.")
for ports in listeports:
i, nbrelow, nbrehigh = 0,0,0
while i<100:
i+=1
etatport=GPIO.input(ports[0])
if etatport==0:
etatport=("LOW")
nbrelow+=1
elif etatport==1:
etatport=("HIGH")
nbrehigh+=1
time.sleep(0.1)
print (str(ports[0])+ "(" + ports[1]+ "): "
+ "Nbre HIGH = " + str(nbrehigh)
+" Nbre LOW = " + str(nbrelow))
destroy() |
Partager