import RPi.GPIO as GPIO import time IR_PIN = 17 # GPIO pin connected to the IR receiver def capture_ir_signals(): print("Capturing IR signals. Press Ctrl+C to stop...") try: while True: pulse_lengths = [] # Wait for the start of a pulse while GPIO.input(IR_PIN) == GPIO.HIGH: pass # Record the start time of the pulse start_time = time.time() # Wait for the end of the pulse while GPIO.input(IR_PIN) == GPIO.LOW: pass # Record the duration of the pulse pulse_duration = time.time() - start_time pulse_lengths.append(pulse_duration) # Continue to record pulse lengths until the signal ends while GPIO.input(IR_PIN) == GPIO.HIGH: start_time = time.time() while GPIO.input(IR_PIN) == GPIO.LOW: pass pulse_duration = time.time() - start_time pulse_lengths.append(pulse_duration) # Decode the pulse lengths decode_signal(pulse_lengths) except KeyboardInterrupt: print("Stopping IR signal capture.") finally: GPIO.cleanup() def decode_signal(pulse_lengths): # Example decoding logic (replace with your own) # This is a very basic example, actual decoding may be more complex print("Received signal:", pulse_lengths) if __name__ == "__main__": GPIO.setmode(GPIO.BCM) GPIO.setup(IR_PIN, GPIO.IN) capture_ir_signals()