empowering creative people

Videos / Circuit Playground Express Workshop - Chapter 4 - Using External Devices

Is your project growing beyond the scope of your onboard LEDs or sensors? In this section, we will discuss connecting external devices to your Circuit Playground Express. We will focus on connecting an external LED strip, and go over how to read and send data to other external devices.

Search Videos

Related Content

Transcript

+

Hi welcome back to this section of the Circuit Playground express online workshop, in this section we're going to learn about how to use external devices with the Circuit Playground Express there's really no limit of things that you can connect to your Circuit Playground Express and you can really unlock a huge potential and new projects once you get it away from the sensors just on the board which there are a lot to work with there. So, let's look at what we're going to see.

I'll show you how to use an external light strip in an external servo with a Circuit Playground. These are driven by a light sensor and are both returning the light level in the room. I have a servo you are driving probably the world's most useless gauge. Alright so let's look at how we're going to do it in MakeCode.

So the first thing we're going to talk about is using external strips with MakeCode, will go into light and then as soon as we click on light a new option appears in its Neopixel and this is how we do strips off the board and the first thing we need to do, is grab whatever animation we want to use for the strip and all the same functions are available for the ring that we've probably used already and then a few extras that are specific to light strips and I guess you'd know them when you need them, I don't want to get too distracted by those now.

So, we'll say we're going to graph the lights a light strip and what we want to graph the light level like we saw. So, I'll graph light level and we'll say we'll graft it up to 70. So, from this alone the light strip won't work because we haven't told the program where the light strip is on the Circuit Playground Express, so we need to go to variables and as soon as you put something down that takes a strip, we'll get the strip variable, which appears in variables. So, we then need to set our strip an on-start block is the best way to do this, so we'll set our strip to and we'll go back to our lights now and we grab this second bubble which is create a strip. So, we'll set the variable strip to create a new strip and I have it connected to A2 and its five pixels.

So now we've told our board where the strip lives and you can reference it using this variable strip anywhere that it appears in the code. We can also do things like set the brightness of the strip and we do that on start as well if we want to set up the strip and initialize it and then we just need to put our strip effects in our forever loop. So that'll get our strip going it's all quite simple and very similar to using just the ring. Now let's talk about other external devices.

So, if we want to use something else besides the light strip we go into advanced and then pins and here we can communicate through any pin we choose through either digital or analog signals pulses or we can do serial communications through the pins as well or in this case we're going to use servos. So, this is a pretty standard servo, so we'll use the servo right command and I'll put that in a forever loop our servos connected to pin A1 and this number in the servo value here is going to represent the angle that the servo is positioned at. So, you change that number it will move to whatever degrees the number is here so 180 is its current position on bright and zero would be on dark.

So, we want to get our light level to be translated into servo motion, but our light level returns a number between 0 and 255, so we're going to use the map function in math, then that changes one range of numbers to another range of numbers and it just keeps the relative value the same. So, we'll get our light level again we'll set it from low and now it will return from 0 to 255 but I checked earlier and it's reading here at about 40 in the room for this level of brightness. So, I'm going to say 40 is bright zero is not bright at all and from low to high it will be zero to 180, so when the light level returns a number between zero and 40 is going to translate that to a number between 0 and 180.

So that wraps up this sketch we'll look at it one more time. So, we're reading the light level in the room and it's returned on this strip, using the graph function. When we cover up the signal the light sensor servo turns toward zero, when we let go it goes back to bright at about 180 and if I pass my hand somewhere in the middle it moves around a little bit.

So that wraps up this section on using external devices with your Circuit Playground Express. Stick around in the next section we're going to learn how to use the console.

comments