i'm using the event mode capture but doesnt' work fine.
i want with this code show pin status from 0 to 1 for Rising and don't show from 1 to 0
instead this casual sometime work fine and other not
with Falling is the same
pin= 4
Input= 1
loop
loop
pin= 4
Input= 1
loop
loop
loop
pin= 4
Input= 1
loop
loop
loop
pin= 4
Input= 1
loop
loop
loop
pin= 4
Input= 1
loop
loop
pin= 4
Input= 0
loop
loop
pin= 4
Input= 1
loop
loop
pin= 4
Input= 0
loop
pin= 4
Input= 1
Code: Select all
#! /usr/bin/python
import time # Importa libreria per la gestione dei timer
# Inizializzazione GPIO
import RPi.GPIO as gpio # Importa libreria GPIO
gpio.setmode(gpio.BCM) # Numerazione BCM
gpio.setwarnings(False) # Disattiva messaggi d'avviso
PinStart = 4
gpio.setup(PinStart, gpio.IN, pull_up_down=gpio.PUD_DOWN) # GPIO4 input, abilita pull-down
# Funzioni
def cambia_stato(pin):
global lampeggio # Importa la variabile globale lampeggio
print("pin=", pin)
print("Input=", gpio.input(4) )
# Interrupt
gpio.add_event_detect(PinStart, gpio.RISING, callback=cambia_stato, bouncetime=200)
print("Ready!")
# Ciclo infinito
while 1:
print ("loop")
time.sleep(0.5) # Aspetta 0.5s
