LED Matrix

Let's go a bit further with programming the LED lights. 


In this step, we'll expand on what we did in the previous step and explore what we can do with different variables.

Start off by creating a new block project for Jay-D and putting three commands that will play animations for left, right, and middle LED display like in the previous step. 

random image

In computer programming, a variable is a storage location that contains a value.
Every variable has a specific name. You can store and change the value of a variable.

Firstly, let's create a variable. Find the section named "Variables" and press the "Create variable..." button.

random image

Now you need to give this variable a name. Let's call this one pos - short for a position on the display. 

random image

random image

When we create a variable, it's undefined - it has no value. We must set a value for every variable when our computer program starts. That's why you'll need the "set variable" block. 

Put this block in the "Arduino run first:" branch.

random image

Now you need to define the value that we want to set the variable to.

Find the block named "123" in the "Math" section. This block is a numerical value block, and you can type in the numerical value you want once you drop it onto the drawing area.

random image

Place the block here:

random image

Now click on the block and type in the value. Set the numerical value of the block to 0. You can do this by simply typing the number 0 (zero) on your keyboard. 

random image

Now that we have a variable created and set to zero, let's change the variable when a certain event is triggered. 

In the next step, we'll show you how to calculate coordinates x and y for the lights on the display. 

Open the "Functions" section and choose to "Create a Function".

random image

A window like the one in the picture should pop up on your screen. Here, you can name the function you're creating.

Since we'll use this to calculate coordinates x and y, let's call it "callXY":

random image

After you named the function, it should appear as a block on the screen with a couple more options to drag and drop into the "Functions" section.

random image

Drag and drop the first "call callXY" block under the "set pos" block:

random image

Now let's define what this function does.

We'll create two new variables just like we did with the "pos" variable.

Go to the "Variables" section and create the following variables: x and y. 

The new variables should appear in this section.

random image

Now drag and drop the "set y to" block here twice:

random image

Since the LED matrixes have 8 rows, we'll use this function to turn on the light in the correct order:
  • set the coordinates by using the drop-down menu: first choose x and then y
  • use the "remainder of" mathematical function to divide the position by 8
  • use "pos" from the "Variables" section
random image

Good job! For now, we have the "Arduino run first" part of the block done.

random image

Let's play with LED lights on a big matrix now.

Go to the "LED matrix" section and choose the "set matrix" block. 

random image

Place the block after "Arduino loop forever".

In the drop-down menu, choose the big LED matrix and set the pixel brightness to 0.

In the x and y line, place the x and y variables as in the following photo:

random image

Now add the blocks shown in the following picture. By adding these books, you will change the position of the LED lights while using logical, variable, and time functions.

random image

Now it's time to run the project so you can see your code in action. 

Click on the Run button on the top right corner of the screen, give a name to your project if you still haven't, and wait for the CircuitBlock to compile the project.

random image

Since the LED matrixes have 8 rows, we'll use this function to turn on the light in the correct order:
  • set the coordinates by using the drop-down menu: first choose x and then y
  • use the "remainder of" mathematical function to divide the position by 8
  • use "pos" from the "Variables" section
random image

Good job! For now, we have the "Arduino run first" part of the block done.

random image

Let's play with LED lights on a big matrix now.

Go to the "LED matrix" section and choose the "set matrix" block. 

random image

Place the block after "Arduino loop forever".

In the drop-down menu, choose the big LED matrix and set the pixel brightness to 0.

In the x and y line, place the x and y variables as in the following photo:

random image

Now add the blocks shown in the following picture. By adding these books, you
will change the position of the LED lights while using logical, variable, and time functions.

random image

Now it's time to run the project so you can see your code in action. 

Click on the Run button on the top right corner of the screen, give a name to your project if you still haven't, and wait for the CircuitBlock to compile the project.