Download a zip of the project by clicking Download Project Bundle below.

After unzipping the file, navigate to Pep_Talk_Generator/clue/CircuitPython v.x/ and copy all of the contents of that directory to the CIRCUITPY drive which appears in your operating system File Explorer or Finder when the Circuit Playground is connected to your computer via a known good USB cable.

# SPDX-FileCopyrightText: 2021 Dylan Herrada for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import random
from adafruit_clue import clue
import displayio
from adafruit_display_text import label, wrap_text_to_pixels
from adafruit_bitmap_font import bitmap_font
import board

column_1 = [
    "Champ, ",
    "Fact: ",
    "Everybody says ",
    "Dang... ",
    "Check it: ",
    "Just saying... ",
    "Superstar, ",
    "Tiger, ",
    "Self, ",
    "Know this: ",
    "News alert: ",
    "Girl, ",
    "Ace, ",
    "Excuse me but ",
    "Experts agree: ",
    "In my opinion, ",
    "Hear ye, hear ye: ",
    "Okay, listen up: ",
]

column_2 = [
    "the mere idea of you ",
    "your soul ",
    "your hair today ",
    "everything you do ",
    "your personal style ",
    "every thought you have ",
    "that sparkle in your eye ",
    "your presence here ",
    "what you got going on ",
    "the essential you ",
    "your life's journey ",
    "that saucy personality ",
    "your DNA ",
    "that brain of yours ",
    "your choice of attire ",
    "the way you roll ",
    "whatever your secret is ",
    "all of y'all ",
]

column_3 = [
    "has serious game, ",
    "rains magic, ",
    "deserves the Nobel Prize, ",
    "raises the roof, ",
    "breeds miracles, ",
    "is paying off big time, ",
    "shows mad skills, ",
    "just shimmers, ",
    "is a national treasure, ",
    "gets the party hopping, ",
    "is the next big thing, ",
    "roars like a lion, ",
    "is a rainbow factory, ",
    "is made of diamonds, ",
    "makes birds sing, ",
    "should be taught in school, ",
    "makes my world go 'round, ",
    "is 100% legit, ",
]

column_4 = [
    "24/7.",
    "can I get an amen?",
    "and that's a fact.",
    "so treat yourself.",
    "you feel me?",
    "that's just science.",
    "would I lie?",
    "for reals.",
    "mic drop.",
    "you hidden gem.",
    "snuggle bear.",
    "period.",
    "can I get an amen?",
    "now let's dance.",
    "high five.",
    "say it again!",
    "according to CNN.",
    "so get used to it.",
]

arial18 = bitmap_font.load_font("/fonts/Arial-18.bdf")
arial12 = bitmap_font.load_font("/fonts/Arial-12.bdf")

arial18.load_glyphs(
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789;,./?><=+[{]}-_"
)
arial12.load_glyphs(
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789;,./?><=+[{]}-_"
)

display = board.DISPLAY
clue_group = displayio.Group()

bitmap_file = open("bmps/background.bmp", "rb")
bitmap1 = displayio.OnDiskBitmap(bitmap_file)
tile_grid = displayio.TileGrid(
    bitmap1, pixel_shader=getattr(bitmap1, "pixel_shader", displayio.ColorConverter())
)
clue_group.append(tile_grid)

text = "\n".join(
    wrap_text_to_pixels(
        random.choice(column_1)
        + random.choice(column_2)
        + random.choice(column_3)
        + random.choice(column_4),
        180,
        arial18,
    )
)
pep = label.Label(
    font=arial18,
    text=text,
    anchor_point=(0.5, 0.5),
    anchored_position=(120, 115),
    line_spacing=0.8,
    color=0x000000,
)
clue_group.append(pep)

title = label.Label(
    font=arial12,
    text="Pep talk generator",
    anchor_point=(0.5, 0.5),
    anchored_position=(120, 231),
    color=0x000000,
)
clue_group.append(title)

display.show(clue_group)

while True:
    if clue.button_a or clue.button_b:
        pep.text = "\n".join(
            wrap_text_to_pixels(
                random.choice(column_1)
                + random.choice(column_2)
                + random.choice(column_3)
                + random.choice(column_4),
                180,
                arial18,
            )
        )

After you've copied all that over, your CIRCUITPY drive should look like this:

CIRCUITPY

Code run-through

The first thing the code does is import all the required libraries.

import random
from adafruit_clue import clue
import displayio
from adafruit_display_text import label, wrap_text_to_pixels
from adafruit_bitmap_font import bitmap_font
import board

Next, the code defines the four lists that will be used to generate the pep talks.

column_1 = [
    "Champ, ",
    "Fact: ",
    "Everybody says ",
    "Dang... ",
    "Check it: ",
    "Just saying... ",
    "Superstar, ",
    "Tiger, ",
    "Self, ",
    "Know this: ",
    "News alert: ",
    "Girl, ",
    "Ace, ",
    "Excuse me but ",
    "Experts agree: ",
    "In my opinion, ",
    "Hear ye, hear ye: ",
    "Okay, listen up: ",
]

column_2 = [
    "the mere idea of you ",
    "your soul ",
    "your hair today ",
    "everything you do ",
    "your personal style ",
    "every thought you have ",
    "that sparkle in your eye ",
    "your presence here ",
    "what you got going on ",
    "the essential you ",
    "your life's journey ",
    "that saucy personality ",
    "your DNA ",
    "that brain of yours ",
    "your choice of attire ",
    "the way you roll ",
    "whatever your secret is ",
    "all of y'all ",
]

column_3 = [
    "has serious game, ",
    "rains magic, ",
    "deserves the Nobel Prize, ",
    "raises the roof, ",
    "breeds miracles, ",
    "is paying off big time, ",
    "shows mad skills, ",
    "just shimmers, ",
    "is a national treasure, ",
    "gets the party hopping, ",
    "is the next big thing, ",
    "roars like a lion, ",
    "is a rainbow factory, ",
    "is made of diamonds, ",
    "makes birds sing, ",
    "should be taught in school, ",
    "makes my world go 'round, ",
    "is 100% legit, ",
]

column_4 = [
    "24/7.",
    "can I get an amen?",
    "and that's a fact.",
    "so treat yourself.",
    "you feel me?",
    "that's just science.",
    "would I lie?",
    "for reals.",
    "mic drop.",
    "you hidden gem.",
    "snuggle bear.",
    "period.",
    "can I get an amen?",
    "now let's dance.",
    "high five.",
    "say it again!",
    "according to CNN.",
    "so get used to it.",
]

After creating the lists for the pep talks, the code loads the fonts. It also loads a few glyphs to make updating the display a bit quicker.

arial18 = bitmap_font.load_font("/fonts/Arial-18.bdf")
arial12 = bitmap_font.load_font("/fonts/Arial-12.bdf")

arial18.load_glyphs(
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789;,./?><=+[{]}-_"
)
arial12.load_glyphs(
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789;,./?><=+[{]}-_"
)

Then, the display gets set up. The initial pep talk is generated and all the necessary bitmaps and text boxes are added to the display group which is then shown on the display.

display = board.DISPLAY
clue_group = displayio.Group()

bitmap_file = open("bmps/background.bmp", "rb")
bitmap1 = displayio.OnDiskBitmap(bitmap_file)
tile_grid = displayio.TileGrid(
    bitmap1, pixel_shader=getattr(bitmap1, "pixel_shader", displayio.ColorConverter())
)
clue_group.append(tile_grid)

text = "\n".join(
    wrap_text_to_pixels(
        random.choice(column_1)
        + random.choice(column_2)
        + random.choice(column_3)
        + random.choice(column_4),
        180,
        arial18,
    )
)
pep = label.Label(
    font=arial18,
    text=text,
    anchor_point=(0.5, 0.5),
    anchored_position=(120, 115),
    line_spacing=0.8,
    color=0x000000,
)
clue_group.append(pep)

title = label.Label(
    font=arial12,
    text="Pep talk generator",
    anchor_point=(0.5, 0.5),
    anchored_position=(120, 231),
    color=0x000000,
)
clue_group.append(title)

display.show(clue_group)

Finally, the code loops through, waiting to see if the user presses one of the buttons on the front of the CLUE. If they do, it generates a new pep talk to display.

while True:
    if clue.button_a or clue.button_b:
        pep.text = "\n".join(
            wrap_text_to_pixels(
                random.choice(column_1)
                + random.choice(column_2)
                + random.choice(column_3)
                + random.choice(column_4),
                180,
                arial18,
            )
        )

This guide was first published on Nov 02, 2021. It was last updated on 2021-11-02 18:52:55 -0400.

This page (Code the CLUE Pep Talk Generator) was last updated on Nov 22, 2021.

Text editor powered by tinymce.