empowering creative people

Videos / Circuit Playground Express Workshop - Chapter 4 - Controlling RGB LEDs

The Circuit Playground Express comes with ten NeoPixel RGB LEDs right on the board. Controlling them with MakeCode is easy! In this section will discuss the various ways to control the NeoPixels, and how to incorporate them into your project!

Search Videos

Related Content

Transcript

+

Hi, welcome back to the Circuit Playground Express online workshop, in this section I'm going to talk to you about using the lights on the Circuit Playground Express. Every Circuit Playground Express has ten Neopixel LEDs baked right in and these are RGB LEDs. So, they're capable of making red, green or blue or combining any of those colours to make any colour that you want. So, I'm going to show you how to make this sketch amongst others just to get you going making simple light animations or making the lights light up however you might want on your Circuit Playground Express.

So, if we look and MakeCode at what I have going here, it brings us to our first light option which is the show ring block. So, we can use the show ring block just to select any colour we want on the colour wheel and change those lights to be that colour just by clicking them or if we select grey then they'll turn off. So this is a quick visual way to make our lights light up in any sort of pattern that we want and I've thrown a pause in here, so there's a slight delay when each light turns on, if you stack up just a bunch of show rings together the program will run through them so fast that it'll just look like everything's flickering and you won't be able to distinguish the different colours from each other.

So the next light option we have if we go into the light menu is show animation, now there are six different animations that we can choose from and I'll just send the rainbow animation to the board and these are nice because making a rainbow animation like this would take a lot of time to work out, so it allows you to have some pretty rewarding animations without needing to grind through them and create them manually. So, you could play around with a different animation the options there, they're fun to throw into your code. We then have set all pixels to a given colour and our graph functions, so I'll show you the graph. Graph is handy because it turns the wheel of lights on the Circuit Playground express into a bar graph, so if I want to take our sound level to live input and put it in graph and we'll say we'll graph the sound level up to 100 then it's going to take readings off the sound level off the microphone in real-time and then turn them into a graph on the board, so as things get louder like as you can see when my voice is loud the bar climbs up the Circuit Playground Express and when it's quiet it stays down near the bottom and that's a really fun feature and you can do that with just about any live data it's good for accelerometers, sound level or light level.

So the next one I want to talk to you about is set brightness and set brightness is best used in a non-start because you don't really need to set the brightness all the time so we would say set brightness and then that returns a value from 0 to 255, it doesn't scale linearly, so you'll find that like as you climb higher it gets a little brighter half of 255, is not half brightness as we see it with our eye I usually keep it around 20, just so I can look at it if you turn it up to 255 it's quite blinding and if you were going to have a battery-powered project the Neopixels will burn up your battery life faster than anything else so it's good to dim them down a bit. So, we have the option to create colours manually using red, green and blue values.

The next section here is our photon command so this is kind of a customizable animation you can change the colour, the speed of how it moves so we'll pick the photon, will say photon forward by 1 and put a pause in there, so we can see it on the virtual board but if we look at the real board we have the photon spins in circles around the board, we can pause it with these commands, in the light menu can have it move faster or slower and we can change its colour. So, say we want to change this photon pen hue to be purple. So, then the pen will be purple, and it looks like it's turning green, but you can set it to any colour you like.

So, the next one is set a specific pixel to set colour. The pixel colour bubble reads the colour at a given pixel that you select, and you can use that elsewhere in your code maybe if you want to copy the colour of a certain pixel. The bubble that has the animation symbol in it is used to send animations to strips and if you want to just show one frame of an animation or maybe make it advance it one frame at a time then you can use this show frame of animation and then the most used to that I think down at the bottom are the stop all animations and clear. If you ever want to turn on a light and then have it turn off afterwards you need to command it off, so it's not going to just turn on and know to turn off when your code continues, so a common trap to fall into is have is to have a light turn on to indicate something and then forget to turn it off again, so it'll just end up staying on forever once it's been turned off once so we avoid that easily by just adding in a clear, when we want our lights to turn back off.

So that wraps up all the light the basic light options in MakeCode. Stick around in the next section, we'll go over some inputs and how to use certain sensors on the board.

comments