Skip to content

Instantly share code, notes, and snippets.

@sudevschiz
Created December 28, 2022 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudevschiz/d4db1394e9f8b9afdefd3978149d0a8f to your computer and use it in GitHub Desktop.
Save sudevschiz/d4db1394e9f8b9afdefd3978149d0a8f to your computer and use it in GitHub Desktop.
Gist to control the servo connected to Raspberry Pi that feeds the fishes at specific time and notify by telegram
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment