For my second video, I decided to investigate arrays. It turns out that Python actually doesn’t have a specific array function; instead, it has a more general “list” function which can be used to do the same thing as an array. However, I think it’s important that we take a step back and investigate arrays in Makecode, since we may never have gotten comfortable with them. This is a basic array:
The three necessary parts of an array in Makecode are 1) define a variable as an array and fill in the values you want the array to store. 2) Create a loop that determines how to run the array. Our array has 6 values starting at 0, so we need to tell the array to run the array from 0-5, hence the length of the list (6) minus 1 = 0-5. 3) Finally, inside the loop determining how to run the array, we need to run the array. So just like other programs, you need to define a variable, create a loop for that variable, and perform an action on that variable.
This next program runs the array, and then runs the array in reverse is light level is below 128. What I learned from this program is that no matter what you do to the array (i.e. tell it to reverse its order), you still need to give it a loop and command, or it won’t output anything. Arrays are simply stored data. They won’t perform any action unless you tell them to.
My third program is very similar, except that the reverse instructions are embedded in the first array loop. This allows me to change the direction in the middle of the array by manipulating the light level. It prepares to run the array, checks the light level, and then then decides which direction to run. If light level is 128 or above, it will skip everything in the while loop and run the forward program. If light level is below 128, it will stay within that while loop, so there is an implied “else” outside the while loop. Something to note is that the program will reverse the direction of the array each time it runs, so you will get an alternating pattern.