Skip to content

Instantly share code, notes, and snippets.

@clcollins
Last active March 16, 2021 19:54
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 clcollins/01ccc2f0946dc46ce4d32dd947c7f6b7 to your computer and use it in GitHub Desktop.
Save clcollins/01ccc2f0946dc46ce4d32dd947c7f6b7 to your computer and use it in GitHub Desktop.
PiDay Countdown Article Changes

In the section "Countdown Logic", replace the code example with this:

def countdown(now):
    piday = datetime(now.year, 3, 14)

    # Add a year if we're past PiDay
    if piday < now:
        piday = datetime((now.year + 1), 3, 14)

    days = (piday - now).days

    logging.info(f"Days till piday: {days}")
    return day

In the section "The Pi Day Countdown Timer", replace the third code example (starts with "while (True):") with this:

    while (True):
        days = countdown(datetime.now())
        unit = get_days_unit(days)

        # Clear the bottom half of the screen by drawing a rectangle filld with white
        piday_draw.rectangle((0, 50, 250, 122), fill = 255)

        # Draw the Header
        piday_draw.text((10,10), "Days till Pi-day:", font = bangers36, fill = 0)

        if days == 0:
            # Draw the Pi Day celebration text!
            piday_draw.text((0, 50), f"It's Pi Day!", font = bangers64, fill = 0)
        else:
            # Draw how many days until Pi Day
            piday_draw.text((70, 50), f"{str(days)} {unit}", font = bangers64, fill = 0)

        # Render the screen
        epd.displayPartial(epd.getbuffer(piday_image))
        time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment