balanga
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

pfio.init()

while(True):
    for pin_number in range(1,3):
        if pfio.digital_read(pin_number) == 0:
            pfio.digital_write(pin_number,1) # Using only the leds
        else:
            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.

http://www.piface.org.uk/products/piface_digital_2/

http://www.piface.org.uk/static/img/pif ... 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.

Cheers.

Return to “HATs and other add-ons”