Skip to content

Instantly share code, notes, and snippets.

@matteoferla
Created November 15, 2020 00:21
Show Gist options
  • Save matteoferla/d96cd76281eb6856cc1efb5046721d98 to your computer and use it in GitHub Desktop.
Save matteoferla/d96cd76281eb6856cc1efb5046721d98 to your computer and use it in GitHub Desktop.
I am unable to remember which colour bin to put on and to put the bin out in the first place... So the Pi does it for me.
# A raspberry pi has a green and a blue LED connected to D23 and D24
# ============== imports =========================================
from apscheduler.schedulers.background import BackgroundScheduler
from functools import partial
from datetime import datetime
import digitalio
import board
import time
# ============== functions ========================================
def binmaster(pin, weekday=3): # my bins go out on Thursday night
with digitalio.DigitalInOut(pin) as led:
while datetime.now().weekday() == weekday:
led.direction = digitalio.Direction.OUTPUT
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
bluebinmaster = partial(binmaster, pin=board.D24)
greenbinmaster = partial(binmaster, pin=board.D23)
# ============== run =========================================
# The job will be executed on November 6th, 2009
scheduler.add_job(greenbinmaster, 'interval', weeks=2, start_date='2020-11-12 16:00:00')
scheduler.add_job(bluebinmaster, 'interval', weeks=2, start_date='2020-11-19 16:00:00')
scheduler.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment