Posts: 118
Joined: Sat Aug 23, 2014 6:56 pm

Please explain some code

Fri Feb 15, 2019 11:01 pm

I pinched some code from somewhere for monitoring a PIR and don't really know how it works....

Code: Select all

# Alarm program by Francesco Balsamo
# Using a PIR sensor with inverted logic

from time import sleep

import pifacedigitalio as pfio
# import piface.pfio as pfio


    for pin_number in range(1,3):
        if pfio.digital_read(pin_number) == 0:
            pfio.digital_write(pin_number,1) # Using only the leds
            pfio.digital_write(pin_number,0) # Disabling only the leds
I'm using an RPi 2 with a PiFace Digital 2 interface and a PIR attached. ... iagram.png

(not sure how to insert diagrams)....

When I run this program the LED in position 1 comes on. When any movement is detected LED 2 comes on for a second or so.

I'm very pleased with this magic which took me ages to come across, but I would like to change it so that only LED 0 is used, ie, it's normally off but comes on when there is movement. If anyone could amend the above code, I would be very grateful.


Return to “HATs and other add-ons”