Skip to main content
ALPHA    This is new software undergoing tests! Thank you for your patience.

Candidate: Claire Candidate claire_candidate Assessed by: Mary Mentor mary_mentor

Python (2023) ~ Grade 1 (Initial)

Mask emote-o-matic

Emote a smile or a frown through your COVID mask with a CircuitPlayground Express and Python.

Attached files
Filename (click to download) Size Uploaded by
cp_frown.jpg 258.4 KB claire_candidate
Markdown code
![cp_frown.jpg](/media/assessment/7ea5619d/2022-03-16/17-50-58/cp_frown.jpg "cp_frown.jpg")
cp_smile.jpg 283.7 KB claire_candidate
Markdown code
![cp_smile.jpg](/media/assessment/7ea5619d/2022-03-16/17-50-58/cp_smile.jpg "cp_smile.jpg")
CodeGrades_MuValueError.png 113.9 KB claire_candidate
Markdown code
![CodeGrades_MuValueError.png](/media/assessment/7ea5619d/2022-03-16/17-50-58/CodeGrades_MuValueError.png "CodeGrades_MuValueError.png")
cp_frown_submit.jpeg 241.0 KB claire_candidate
Markdown code
![cp_frown_submit.jpeg](/media/assessment/7ea5619d/2022-03-16/17-55-43/cp_frown_submit.jpeg "cp_frown_submit.jpeg")
cp_smile_submit.jpeg 213.5 KB claire_candidate
Markdown code
![cp_smile_submit.jpeg](/media/assessment/7ea5619d/2022-03-16/17-55-43/cp_smile_submit.jpeg "cp_smile_submit.jpeg")
cp_paper_frown.jpeg 161.7 KB claire_candidate
Markdown code
![cp_paper_frown.jpeg](/media/assessment/7ea5619d/2022-03-16/18-16-31/cp_paper_frown.jpeg "cp_paper_frown.jpeg")
cp_paper_smile.jpeg 164.6 KB claire_candidate
Markdown code
![cp_paper_smile.jpeg](/media/assessment/7ea5619d/2022-03-16/18-16-31/cp_paper_smile.jpeg "cp_paper_smile.jpeg")
mask-emote-o-meter-user-guide.pdf 32.4 KB claire_candidate
Markdown code

Status: Closed (results delivered). 80/100 ~ Pass with MERIT (17/03/2022).

View full results


claire_candidate Claire Candidate ~ 16 Mar 2022 5:49 p.m.

I'm going to make a COVID mask emote-o-matic.

During lock-down I've noticed that it's hard to tell a person's mood through their masks. Put simply, you can't see them smile or look sad, because it's sometimes hard to tell with just the person's eyes.

I'm going to sew an Adafruit Circuit Playground Express into my mask to learn how feasible an emote-o-matic is for people. As you can see from the photo, the board comes with lights and two buttons - so pressing the right button will turn the device into either a happy (the lower lights in green) or sad (the upper lights in red) look.

Adafruit Circuit Playground Express

I think it's going to look cute and will make mask wearing something fun rather than a bit of a chore.


claire_candidate Claire Candidate ~ 16 Mar 2022 5:50 p.m. (updated: 16 Mar 2022 5:51 p.m.)

I've been looking at Adafruit's CircuitPython Essentials to try to work out how to use the lights (called NEOPIXELS) and the buttons. I also found the CircuitPython examples for the NEOPIXELS. It has been hard trying to get things to work since none of it makes any sense! I just wanted to make the NEOPIXELS switch on with various colours but nothing happened. In the end I saw that my code had errors:

I wasn't sure to do, so I searched for "ValueError: NEOPIXEL is in use" and the top result was this comment somewhere. I didn't really understand much of what was going on, but I guessed that I couldn't use neopixel AND cpx at the same time. The example at the end gave me the hint I needed to make things work and so onto the next challenge.

CodeGrades_MuValueError.png

Each neopixel has a number, and it's REALLY confusing that it starts counting at zero and ends at nine. Also, the order of counting is in an anti-clockwise direction, which is really confusing too. In any case I've managed to figure out how colour works: there are three numbers between 0-255 which tell the light how much red, green or blue to emit. So, (255, 0, 0) means full on red, with no green or blue.

Now the position of the lights was worked out, and the colours too I was able to make a smile like this:

from adafruit_circuitplayground.express import cpx

cpx.pixels[0] = (0, 0, 0)
cpx.pixels[1] = (0, 0, 0)
cpx.pixels[2] = (0, 255, 0)
cpx.pixels[3] = (0, 255, 0)
cpx.pixels[4] = (0, 255, 0)
cpx.pixels[5] = (0, 255, 0)
cpx.pixels[6] = (0, 255, 0)
cpx.pixels[7] = (0, 255, 0)
cpx.pixels[8] = (0, 0, 0)
cpx.pixels[9] = (0, 0, 0)

and a frown like this:

from adafruit_circuitplayground.express import cpx

cpx.pixels[0] = (255, 0, 0)
cpx.pixels[1] = (255, 0, 0)
cpx.pixels[2] = (255, 0, 0)
cpx.pixels[3] = (0, 0, 0)
cpx.pixels[4] = (0, 0, 0)
cpx.pixels[5] = (0, 0, 0)
cpx.pixels[6] = (0, 0, 0)
cpx.pixels[7] = (255, 0, 0)
cpx.pixels[8] = (255, 0, 0)
cpx.pixels[9] = (255, 0, 0)

Here's a couple of photos to show how it looks with my mask:

cp_smile.jpg

cp_frown.jpg

I'm feeling really happy that I've made the device look happy and sad.

Next step is to make it change mood depending on which button you press.

I've already shown some friends who really like it!


claire_candidate Claire Candidate ~ 16 Mar 2022 5:55 p.m. (updated: 16 Mar 2022 5:56 p.m.)

I've finally worked out how to make the buttons work so the smile changes. Here's how:

I think I have a minimal working project! Time to submit.

"""
COVID Mask emote-o-matic.

Run a CircuitPlayground Express running CircuitPython.
Put the board in a COVID mask and attach power.

Press button A for a green smile.
Press button B for a red frown.

Emote away! :-)
"""
from adafruit_circuitplayground.express import cpx

smile = False
frown = False

cpx.pixels.brightness = 1.0

while True:
    if cpx.button_a == True:
        if smile == True:
            smile = False
        else:
            smile = True
        frown = False
    elif cpx.button_b == True:
        if frown == True:
            frown = False
        else:
            frown = True
        smile = False
    if smile == True:
        cpx.pixels[0] = (0, 0, 0)
        cpx.pixels[1] = (0, 0, 0)
        cpx.pixels[2] = (0, 255, 0)
        cpx.pixels[3] = (0, 255, 0)
        cpx.pixels[4] = (0, 255, 0)
        cpx.pixels[5] = (0, 255, 0)
        cpx.pixels[6] = (0, 255, 0)
        cpx.pixels[7] = (0, 255, 0)
        cpx.pixels[8] = (0, 0, 0)
        cpx.pixels[9] = (0, 0, 0)
    elif frown == True:
        cpx.pixels[0] = (255, 0, 0)
        cpx.pixels[1] = (255, 0, 0)
        cpx.pixels[2] = (255, 0, 0)
        cpx.pixels[3] = (0, 0, 0)
        cpx.pixels[4] = (0, 0, 0)
        cpx.pixels[5] = (0, 0, 0)
        cpx.pixels[6] = (0, 0, 0)
        cpx.pixels[7] = (255, 0, 0)
        cpx.pixels[8] = (255, 0, 0)
        cpx.pixels[9] = (255, 0, 0)
    else:
        cpx.pixels.fill((0,0,0))

I've attached the code to this comment (main.py) and here's a couple of photos of it in action with my "test mask":

cp_smile_submit.jpeg

cp_frown_submit.jpeg


mary_mentor Mary Mentor ~ 16 Mar 2022 6:14 p.m.

Hi Claire,

I'm Mary and I'm going to be your mentor. I really like what you've been doing with this grade 1 project. Very timely and imaginative.

My job is to help you improve your project and assess how you've got on with your grade 1. One thing I won't do is contribute code, but I will ask questions, make suggestions, point out bugs and share things I think you'll find interesting to help you refine your project.

I've a few initial questions, items of feedback and observations. Please don't hesitate to ask questions or tell me where something doesn't make sense, I'm here to help.

I'm looking forward to seeing how this project shapes up. Once again, congratulations for all the work you've done so far.


claire_candidate Claire Candidate ~ 16 Mar 2022 6:16 p.m. (updated: 16 Mar 2022 6:17 p.m.)

Hi Mary, pleased to meet you and I'm really happy you like the project.

Thank you so much for the feedback and questions.

cp_paper_smile.jpeg

cp_paper_frown.jpeg

Here's the revised code:

"""
COVID Mask emote-o-matic.

Use a CircuitPlayground Express running CircuitPython.
Put the board in a COVID mask and attach power.

Press button A for a green smile.
Press button B for a red frown.
Press both buttons to turn off.

Emote away! :-)
"""
from adafruit_circuitplayground.express import cpx

smile = False
frown = False

cpx.pixels.brightness = 0.1

while True:
    if cpx.button_a and cpx.button_b:
        smile = False
        frown = False
    elif cpx.button_a:
        smile = True
        frown = False
    elif cpx.button_b:
        frown = True
        smile = False
    if smile:
        cpx.pixels.fill((0, 0, 0))
        cpx.pixels[0] = (0, 255, 0)
        cpx.pixels[1] = (0, 255, 0)
        cpx.pixels[2] = (0, 255, 0)
        cpx.pixels[3] = (0, 255, 0)
        cpx.pixels[4] = (0, 255, 0)
    elif frown:
        cpx.pixels.fill((0, 0, 0))
        cpx.pixels[5] = (255, 0, 0)
        cpx.pixels[6] = (255, 0, 0)
        cpx.pixels[7] = (255, 0, 0)
        cpx.pixels[8] = (255, 0, 0)
        cpx.pixels[9] = (255, 0, 0)
    else:
        cpx.pixels.fill((0, 0, 0))

mary_mentor Mary Mentor ~ 16 Mar 2022 6:17 p.m.

Hi Claire,

So your bug is a common one and I can tell you what to search for online to find a solution.

Put simply, you don't remove you fingers from the buttons at exactly the same time. It means, for a fraction of a second, you have only one button pressed, thus causing the emote related to that button to display. This is because you have the while True: loop repeating so fast that it detects these slight differences in timing when you release the buttons.

If I were you, I'd search online for ways to make the CircuitPython sleep for a fraction of a second on each iteration of the while True: loop.

Also, I have a question about your revised code: do you need to repeat the cpx.pixels.fill((0, 0, 0)) line three times?

I look forward to your user manual!


claire_candidate Claire Candidate ~ 16 Mar 2022 6:18 p.m.

Hi Mary,

I fixed the bug! I'm so happy!

It took a while, but I found out about time.sleep which pauses the program. By putting this in the if statement relating to both buttons being pressed I was able to slow down the loop enough so the over-sensitive checking of buttons is no longer an issue. Through trial and error I found that using a float value for fractions of a second of 0.1 was the best setting.

I was stumped for a while, but you're right... I only need to clear the lights once, and I was able to remove the final else: as a result.

I'm putting together a user manual now and will attach it in a moment.

Here's the final version of the code.

"""
COVID Mask emote-o-matic.

Use a CircuitPlayground Express running CircuitPython.
Put the board in a COVID mask and attach power.

Press button A for a green smile.
Press button B for a red frown.
Press both buttons to turn off.

Emote away! :-) :-(
"""
import time
from adafruit_circuitplayground.express import cpx

smile = False
frown = False

cpx.pixels.brightness = 0.1

while True:
    if cpx.button_a and cpx.button_b:
        smile = False
        frown = False
        # Pause the loop to avoid over-sensitive buttons.
        time.sleep(0.1)
    elif cpx.button_a:
        smile = True
        frown = False
    elif cpx.button_b:
        frown = True
        smile = False
    # Turn off all the lights.
    cpx.pixels.fill((0, 0, 0))
    # Only switch on the lights that are needed.
    if smile:
        cpx.pixels[0] = (0, 255, 0)
        cpx.pixels[1] = (0, 255, 0)
        cpx.pixels[2] = (0, 255, 0)
        cpx.pixels[3] = (0, 255, 0)
        cpx.pixels[4] = (0, 255, 0)
    elif frown:
        cpx.pixels[5] = (255, 0, 0)
        cpx.pixels[6] = (255, 0, 0)
        cpx.pixels[7] = (255, 0, 0)
        cpx.pixels[8] = (255, 0, 0)
        cpx.pixels[9] = (255, 0, 0)

claire_candidate Claire Candidate ~ 16 Mar 2022 6:19 p.m.

OK. I've written a user guide (PDF attached). I've imagined it like the sort of gizmo you get advertised on naff shopping channels and daytime TV.


mary_mentor Mary Mentor ~ 16 Mar 2022 6:20 p.m.

Claire,

Thank you so much for the updates. I think I have enough evidence to assess your project. Your results should come through in the next day or two.


claire_candidate Claire Candidate ~ 16 Mar 2022 6:20 p.m.

Thank you so much for all your help and support. I'm nervous to find out my result.


Back to top