I am trying to create code that should initiate an interrupt when gpio 21 is high, to take the binary data from the other two gpios and store it in a text file. The problem is that it doesn't take the interruption...
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # formato para utilizar los pines de la rasberry
Clock = 21
Data1=23
Yb=24
flag=False
GPIO.setup(Clock,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(Data1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(Yb,GPIO.IN,pull_up_down=GPIO.PUD_UP)
archivo = open("datos.txt", "a")
contador=0
def captura (channel):
flag=True
contador=1
GPIO.add_event_detect(Clock, GPIO.RISING,callback=captura)
t=time.time()
while (time.time()-t<5):
if flag==True:
salida=str(int(GPIO.input(Data1)))
salida=salida+' '+str(int(GPIO.input(Yb)))+'\n'
flag=False
archivo.write(salida) #inte
archivo.close()
print(contador)
I add in method captura a counter to check if it works
contador=0
def captura (channel):
flag=True
contador=1