Marquee lights are fancy, eye-catching lighting displays used by cinemas, theatres and shops. So lets program our GlowBit™ Rainbow & Micro:bit with an animated marquee 'chasing' pattern.

Transcript

G'day, I'm going to show you how to animate this LED marquee display using your GlowBit Rainbow. Stick around to the end for a little creative art project as well.

Let's get started. We'll start by wiring our rainbow to our micro bit. I'll use black for ground, ground on the Micro:Bit, ground on the rainbow, red for three volts and yellow for data. That's pin zero on the Micro:bit and data on the rainbow.

Connect your Micro:bit to your computer with a USB lead. And with your browser, navigate to python.MicroBit.org. And this is our MicroPython programming environment. This looks like the default project. I'm not going to need any of this code. And the first thing I'll do is import NeoPixel. GlowBits are compatible with the NeoPixel driver library. I'll declare my rainbow.

Great, so I think this project has two steps. The first is to light up every third LED. And then the second step is to make that animation. So I know that under while true, I'll want to clear the rainbow every loop. And we're also going to do some decision making for every LED in the rainbow. So I'll need a for loop for index I in range, and we have 13 LEDs.

And this is where we'll check if we're working on every third LED. We'll do that using the mod operator. This allows us to divide two numbers and check the remainder. If the remainder is zero, then we know that we have an even multiple. So if we divide something by three, and the remainder is zero, we know we're working with every third number. And we type that with if I mod three equals zero. So in plain English, this means if I divided by three has a remainder of zero, that's like saying for every third LED, we want to light that LED up. Rainbow, the i-th, the i-th LED in the rainbow equals,And we'll make some nice violet colour 60, 33, 60. So that's 60 red, 33 green, and 60 blue.

So we can break out of that loop and out of the first loop and say rainbow show, rainbow.show.

We can connect to the Micro:Bit, select it from the pop up menu and hit flash.

All right, I'll bring in this piece of colored plastic. You can't see it otherwise, but there we have a static pattern of every third LED lit.

So that's number zero. So zero divided by three is zero with a remainder of zero. So this one's lit. One has a remainder of one, two has a remainder of two, three divided by three has a remainder of zero. So that LED is lit. It looks like everything is working as it should be.

We are on the home stretch. We just need to animate it. I'll create a variable called counter, counter equals zero. And I know that every loop I want to increment that counter. This is like incrementing the frame of animation.

And to get our pattern to move, we'll apply that counter, which is kind of like an offset here in this if statement. If I minus counter mod three equals zero. And I'll include a delay right at the end with sleep 200. Hit flash.

And just like that, we have a beautiful animated marquee display.

All right. We can even change the direction by changing this minus to a plus. That ought to reverse the direction that it appears these LEDs move in. And there we go. Before they were moving from the left to the right, and now it looks like they're moving from the right to the left. That's pretty cool.

So what's going on with this counter variable? How is it actually animating this pattern? Well, since it's incrementing every loop and it's being used in our condition here, all it's really doing is offsetting for which LED this statementIs true every loop. When counter is zero, this statement is true for every third LED starting at the zeroth. When counter is one, that's shifting all the LEDs that the statement is true for. So every time we loop, it's basically shifting by one, the pattern of LEDs that this statement is true for.

And there you have a beautiful LED marquee display using a few simple math tricks. I hope you learned something. I know I did. I'll see you in the next project.

All right, got a happy little person juggling some, some bright LED balls. Nice one. Couldn't resist. See you in the next project. Bye.

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.