Codes

Retrouvez ici mes différents scripts et morceaux de code.

FICHIERS :
				
# Nicolas Colsoul
# V1 : 08/02/2019
# Petit script qui gère la mise en route des IOs ainsi que la télécommande de PiEtendard
# A lancer dans un screen indéfiniment : plus besoin de 4 scripts parallèles.
# Warning : code en mousse !

import RPi.GPIO as GPIO
import subprocess
import os
import time

pinRead = [28, 6, 27, 4]
pinWriteA = [17, 22, 5, 6]
pinWriteB = [0, 3, 21, 22]


GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

# IN/OUT de chaque IO connecté
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(6, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(14, GPIO.IN)
GPIO.setup(15, GPIO.IN)
GPIO.setup(18, GPIO.IN)
GPIO.setup(25, GPIO.IN)


stateList = [0, 0, 0, 0]
statusList = [False, False, False, False]

# Gestion de la télécommande.
while True:
	stateList[0] = os.popen("gpio -g read 14").read()
	stateList[1] = os.popen("gpio -g read 15").read()
	stateList[2] = os.popen("gpio -g read 18").read()
	stateList[3] = os.popen("gpio -g read 25").read()
	
	i = 0
	for s in stateList:
		if("1" in str(s)):
			statusList[i] = True
			print "SWITCH " + str(i)
		if statusList[i]:
			state = os.popen("gpio read " + str(pinWriteB[i])).read()
			if("1" in str(state)):
				GPIO.output(pinWriteA[i], False)
			else:
				GPIO.output(pinWriteA[i], True)
			print "CHANGE"
			statusList[i] = False
		i = i + 1
	
	time.sleep(1)