# ==================================================
"""
Project objective: Blink four external LEDs connected to the Raspberry Pi Pico
Hardware and connections used:
Anode of four LEDs to GPIO pins 6-9 of Raspberry Pi Pico
220 ohm resistor connected in series to each LED
Author: Adrian Josele G. Quional
"""
# ==================================================
# modules
from machine import Pin
from time import sleep
# setting GPIO Pins 6-9 as OUT
# note: any GPIO pin can be used
LED1 = Pin(6, Pin.OUT)
pir = Pin(7, Pin.IN)
# La broche PWM du servomoteur est connectée à la broche GP15 de la Pi Pico
servo = machine.PWM(machine.Pin(8))
#LED2 = Pin(7, Pin.OUT)
#LED3 = Pin(8, Pin.OUT)
#LED4 = Pin(9, Pin.OUT)
# réglage de la fréquence à 50 Hertz, valeur qui peut être différente selon le servomoteur
servo.freq(50)
# continuously blink all 4 LEDs at the same time while the board has power
while True:
if pir.value() == 1:
print(f"PIR value: {pir.value()} Status: Motion detected!")
print("voila 1")
LED1.on()
servo.duty_u16(1500) # position du servomoteur à un angle de 0 degrés (valeur minimale = 1500)
sleep(3)
else:
print(f"PIR value: {pir.value()} Status: Waiting for movement...")
print("voila 2")
LED1.off()
servo.duty_u16(8000) # position du servomoteur à un angle de 180 degrés (valeur maximale = 8000)
sleep(3)