from machine import Pin, Timer
from time import sleep
from picozero import pico_led
from picozero import Servo # importing Servo class to easily control the servo motor
# Hardware and connections used:
# Servo GND to Raspberry Pi Pico GND
# Servo V+ to Raspberry Pi Pico 3.3 V
# Servo PWM pin to GPIO Pin 15
led_green = Pin(14, Pin.OUT, value=0)
led_red = Pin(13, Pin.OUT, value=0)
led_blue = Pin(12, Pin.OUT, value=0)
button1 = Pin(1, Pin.IN, Pin.PULL_UP)
contact1 = Pin(5, Pin.IN, Pin.PULL_UP)
contact2 = Pin(9, Pin.IN, Pin.PULL_UP)
servo_gate = Servo(15)
while True:
# Servo und LEDs zurücksetzen
servo_gate.mid()
led_green.off()
led_blue.off()
led_red.off()
catch_status = 0
maingate_passed = 0
# Funktion warten auf Aktivierung
print ("Warten auf Aktivierung der Falle")
while button1.value() == 1:
# Bereitschaft - grüne LED blinkt
if contact1.value() == 1 and contact2.value() == 1:
led_green.on()
sleep(0.5)
led_green.off()
sleep(0.5)
# Bei Störung von contact1 Fehlercode 1 x rot blinken
elif contact1.value() == 0 and contact2.value() == 1:
led_red.on()
sleep(0.5)
led_red.off()
sleep(0.5)
# Bei Störung von contact2 Fehlercode 2 x rot blinken
elif contact1.value() == 1 and contact2.value() == 0:
led_red.on()
sleep(0.2)
led_red.off()
sleep(0.2)
led_red.on()
sleep(0.2)
led_red.off()
sleep(0.5)
led_green.on()
print ("Falle scharf gestellt")
# Funktion zur Alarmkontakte-Auswertung
while catch_status == 0:
if contact1.value() == 0 and contact2.value() == 1 and maingate_passed == 0:
led_green.off()
led_red.off()
led_blue.on()
maingate_passed = 1
print ("Falle betreten")
elif contact1.value() == 1 and contact2.value() == 0 and maingate_passed == 1:
led_green.off()
led_blue.off()
led_red.on()
print ("AUSLÖSUNG")
catch_status = 1
# Gefangen!
servo_gate.max()
print ("GEFANGEN!")
print ("Email send")
# Warten auf Neustart - 3 Sekunden Status-Button drücken!
print ("Warten auf Neustart")
while button1.value() == 1:
sleep(3)
while button1.value() == 0:
sleep(1)
print ("Neustart")