Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Last active January 9, 2017 02:59
Show Gist options
  • Save oscarmorrison/552a9a9fc2664bd3578cece680d77c9c to your computer and use it in GitHub Desktop.
Save oscarmorrison/552a9a9fc2664bd3578cece680d77c9c to your computer and use it in GitHub Desktop.
#blog.oscarmorrison.com
#Cat feeder (open and close server)
#change the pin, and port here.
from flask import Flask, jsonify
import RPi.GPIO as IO
import time
pinOut = 4
app = Flask(__name__)
@app.route('/')
def index():
return jsonify(response='pinging from the cat feeder!')
@app.route('/open')
def openRouteWithDefaultTime():
time = 0.5
openFeeder(time)
return jsonify(response='feeding the kitty '+str(time))
@app.route('/open/<time>')
def openRoute(time):
time = float(time)
openFeeder(time)
return jsonify(response='feeding the kitty '+str(time))
def openFeeder(wait):
print('Opening cat feeder for ', wait)
IO.setwarnings(False)
IO.setmode (IO.BCM)
IO.setup(pinOut,IO.OUT)
pwm = IO.PWM(pinOut,50)
pwm.start(2.5)
time.sleep(0.5)
pwm.ChangeDutyCycle(7.5)
time.sleep(wait)
pwm.ChangeDutyCycle(2.5)
time.sleep(0.5)
pwm.stop(2.5)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment