7

(avery) #1

Colour-sensing clutch with Circuit Playground Express


SCHOOL OF MAKING


Variables menu. Drag the ‘Set strip to 0’ block into the
On Start loop.
Click on the Light menu to reveal the nested
NeoPixel menu. Click on NeoPixel to view more
options for strips. Find the round module labelled
‘Create strip on A1 with 24 pixels’ and drag it onto
the workspace. Drop it onto the ‘Set strip to 0’ block,
directly on top of the ‘0’. From now on in our code,
the variable ‘strip’ is the placeholder for the NeoPixel
strip we have connected to pin A1. Change the
number 24 to the actual number of LEDs on your strip
(ours was 12).

One other setup item we need to address is setting
the thresholds for the light sensor. Depending on
the amount of light in your environment, you may
need to experiment with these settings to get a good
reading from the light sensor. Even if yours works
great right from the start, it’s good to know where
these settings are, because chances are you’ll need
to tweak them eventually.
The light sensor is an input, so head into the Input
menu and scroll down to find the ‘Set dark threshold
value to 0’ block. Drag this block into the On Start

loop, and just leave the value at 0 for now. Duplicate
the block by right-clicking and selecting ‘duplicate’.
Drag the new block into place right underneath
the first one, and click on the drop-down menu to
change ‘dark’ to ‘bright’. Leave this one at 0 for
now also. Later on, if you’ve downloaded the code
to your Circuit Playground Express and the sensor
doesn’t seem to be responding correctly, you can
adjust these threshold values until the sensor works
well in your particular lighting conditions.

MAKE A STARTUP SEQUENCE
Now let’s create a startup sequence so that we
know the lights are working when we turn on the
Circuit Playground Express. Head into the Light
menu and grab the ‘Show rainbow animation
for 500 ms’ block. Add it to the On Start block,
and click on the drop-down menu to change the
duration from 500 ms to 1 second. In the Circuit
Playground Express simulator, you’ll see that we
just programmed the on-board NeoPixels to show
a rainbow animation. Let’s also make the NeoPixel
strip on pin A1 show the same animation.
Click on the Light menu again to get to the
NeoPixel menu, and find the ‘strip show rainbow
animation for 500 ms’ block. Drag it into the On Start
loop under the previous animation, and change the
duration to 1 second. Although you won’t see it in
the simulator, our NeoPixel strip will now show the
same animation as the on-board NeoPixels.

Depending on the amount of light in your environment,
you may need to experiment with these settings to get
a good reading from the light sensor



Right
Match your clutch
bag with clothes
or accessories
Free download pdf