Skip to content

Instantly share code, notes, and snippets.

@sudevschiz
Created December 28, 2022 15:26
Show Gist options
  • Save sudevschiz/d4db1394e9f8b9afdefd3978149d0a8f to your computer and use it in GitHub Desktop.
Save sudevschiz/d4db1394e9f8b9afdefd3978149d0a8f to your computer and use it in GitHub Desktop.

Revisions

  1. sudevschiz created this gist Dec 28, 2022.
    46 changes: 46 additions & 0 deletions feed_fish.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    import pigpio
    from time import sleep, strftime

    from telegram.ext import Updater

    BOT_TOKEN = ""
    CHAT_ID = ""

    # Pin
    PIN = 17
    # Rest Position (Feeder is upright)
    REST = 2500
    # Down Position
    DOWN = 500

    # Feeding times
    feed_times = ["09:00" ,"18:00"]

    # connect to the pin
    pi = pigpio.pi()

    def feed():
    pi.set_servo_pulsewidth(PIN, DOWN)
    sleep(1)
    pi.set_servo_pulsewidth(PIN, REST)
    sleep(1)
    pi.set_PWM_dutycycle(PIN, 0 )
    pi.set_PWM_frequency(PIN, 0 )

    def notify(t):
    """
    Notify by telegram bot
    """
    updater = Updater(BOT_TOKEN, use_context=True)
    updater.bot.send_message(chat_id=CHAT_ID, text=f"Fed the fishes at {t}!")
    updater.stop()


    # Feed at 9am and 6pm
    while True:
    time = strftime("%H:%M")
    if time in feed_times:
    feed()
    notify(time)
    sleep(62)