Awesome design! Here is my build using a rpi pico, 6mm momentary button and an R/C servo. Coded with circuitpython. Requires importing the "servo" library from adafruit_motor module available within the adafruit library bundle: https://circuitpython.org/libraries.
If the button is pressed, an additional serving of food is delivered without resetting the time delay.
import time import board import pwmio from adafruit_motor import servo import digitalio # create a PWMOut object on Pin gpio2. pwm = pwmio.PWMOut(board.GP2, duty_cycle=2 ** 15, frequency=50) # Create a servo object, my_servo. my_servo = servo.Servo(pwm) # create a digital io object on pin gpio3. btn1_pin = board.GP3 # create a button object, btn1 btn1 = digitalio.DigitalInOut(btn1_pin) # define servo stops feedstop = 90 fillstop = 140 # define frequency of feeding in seconds. 86400 = 24 hours. timedelay = 86400 while True: my_servo.angle = feedstop # moves servo to dispense food time.sleep(2) my_servo.angle = fillstop # moves servo to fill food portion i = 0 for i in range(0, timedelay): # for loop to allow for button interuption time.sleep(1) # sleeps for 1 second increments i += 1 if btn1.value: # accepts button press that performs an additional feeding my_servo.angle = feedstop time.sleep(2) my_servo.angle = fillstop continue # continues for loop so that the 24 hour cycle continues. # This does not reset the 24 hour delay. (edited)
Awesome design! Here is my build using a rpi pico, 6mm momentary button and an R/C servo. Coded with circuitpython. Requires importing the "servo" library from adafruit_motor module available within the adafruit library bundle: https://circuitpython.org/libraries.
If the button is pressed, an additional serving of food is delivered without resetting the time delay.
pi pico case: https://www.thingiverse.com/thing:4924948
https://www.printables.com/model/407625-raspberry-pi-pico-snap-together-case-with-slot-for
button case: https://www.thingiverse.com/thing:106422
using a brass nail hotglued to horn as actuator.
code:
import time
import board
import pwmio
from adafruit_motor import servo
import digitalio
# create a PWMOut object on Pin gpio2.
pwm = pwmio.PWMOut(board.GP2, duty_cycle=2 ** 15, frequency=50)
# Create a servo object, my_servo.
my_servo = servo.Servo(pwm)
# create a digital io object on pin gpio3.
btn1_pin = board.GP3
# create a button object, btn1
btn1 = digitalio.DigitalInOut(btn1_pin)
# define servo stops
feedstop = 90
fillstop = 140
# define frequency of feeding in seconds. 86400 = 24 hours.
timedelay = 86400
while True:
my_servo.angle = feedstop # moves servo to dispense food
time.sleep(2)
my_servo.angle = fillstop # moves servo to fill food portion
i = 0
for i in range(0, timedelay): # for loop to allow for button interuption
time.sleep(1) # sleeps for 1 second increments
i += 1
if btn1.value: # accepts button press that performs an additional feeding
my_servo.angle = feedstop
time.sleep(2)
my_servo.angle = fillstop
continue # continues for loop so that the 24 hour cycle continues.
# This does not reset the 24 hour delay. (edited)