The Adafruit Circuit Playground Express comes equipped with an analog light sensor, but it can be used for much more than just sensing light or darkness! The light sensor has a similar spectral response to the human eye. Its connected to analog pin A8 and will return a value between 0 and 1023. A normal indoor light level reading is about 300, with higher numbers being brighter.

Transcript

Hi, Steven here from Core Electronics, in this tutorial I'm going to show you how to use the light sensor on the Adafruit Circuit Playground Express.

To make a colour matching light wheel and we're going to use MakeCode to do it. On the top left corner of every Circuit Playground Express, there's an analog light sensor and this is capable of reading light or dark, but there are some other exciting things you can do with a light sensor and one of them is to read colour. So, we'll use the light next to the light sensor it'll run through a cycle of red, green and blue and the light sensor will measure the reflected light on each colour and then we'll be able to use that to determine what colour the object was that was right above it.

Another thing you can do with a light sensor is read your pulse by holding your finger over the light sensor and have a white light from the LED next to it and then the license will be able to measure the dips in brightness every time your heart beats and more blood pumps through your finger but today we're going to stick with colour sensing.

So just to give you an example of what we can expect when you hold an object directly over the sensor and hit the B button, it will run through the three colours on the nearest LED and measure how much light is reflected on each colour and use that to generate an RGB value to light up the string of neopixels.

So, let's look at MakeCode, see how we do it. In MakeCode this code is going to be a little different than normal because we won't use the forever loop that's normally in the top-left of every new workspace, so go ahead and get rid of that. We're going straight to inputs, now these first five inputs have the same bracket shape as the forever loop because they are essentially loops we're going to use the on bucket button A click and we'll get two of those because the other one will become button B and anything in the brackets the program is going to look continuously, while the board is powered for a click from button A or button B and then execute whatever's inside, whenever it detects a click. So, it runs exactly like a loop with an if-statement in it, but this is just a little more direct.

So, on button A, click we're going to go into lights and set all pixels to a colour and then on input we have a bubble down here for ambient colour. So this is one of the ways that make code really shines, is that we're able to get some very impressive programs already built natively into this drag-and-drop interface, if you're interested in seeing how this is done in Circuit Python it's actually quite a bit of code and quite a bit of math just to do what's in this little bubble that we've dragged in, but in "M" for button B, we're going to drag it clear, so I've got those backwards we'll make this button B and this one button A. So, whenever we press button B will do a check for the ambient colour and whenever we push button A it will clear the readings, and this is handy because if you do a check for ambient colour while the lights are already lit up another colour then it can throw your results off a little bit.

So, to put that on to our device we just hit download and because our Circuit Playground Express is already connected it downloads automatically if we're using the Windows App Store version of the MakeBlock or a MakeCode IDE.

So, if we a look again hit the B button and hold an object just above the board so it's touching it or just off touching it and then we got a good colour match and we'll just clear it between each colour, check.

So if you're curious about how to make this same program using Circuit Python, I've got another tutorial video up that details all the code required in order to get the same result and let me tell you it's a lot more typing, but if you're a beginner programmer or an educator using MakeCode you can get really good results and a great fun project with just a few clicks and be able to get people excited about learning to program.

So, thanks for watching.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.