In my simple code, I chose to incorporate a specific concept of the loop function. That specific piece is known as the “while true” loop which has a condition that evaluates to a boolean value. Similar to other boolean functions, the loop runs on the “all or nothing” principle.” The condition will run first before the code, if it is true the code inside will run, but if it is false then it will not run. In my previous response, I used another type of boolean function known as the if else statement. By learning a few things from that program, I was able to use similar knowledge to code with animations, sound level, and light level. Now in this program, I begin with the while do loop and plug in a logic comparison value into my true statement. My sound level will then be compared to a numerical value which is greater than 180. The sound level values range from 0 to 250, so we can say that if a loud sound is made then the CPX will respond to that sound with an animation. In addition, if you look at my program you will notice that the animation already accounts for the 500 ms of time that it will stay on. So, that means I will not need to add a pause like I would for most pixels or color blocks.
In the slightly more complex code, I decided to add another element to the program. The code is remotely similar to my original code however, we now add a new logic function so that we can include the light level. The logic function I used was the boolean “and” function which I again placed into the true statement. With this, I can include the light level at values less than 128. This means that when the sound level is greater than 180, considered a loud sound, and the light level is fairly dark, we will see the rainbow animation. Another slight change I made was that the animation will only last for one second instead of two. I am curious to see if the CPX will pick up a combination of the light level and sound under these specific circumstances in the environment.
My third and final code is different in a few ways from my first two programs. In my first two codes, I had placed my full program in the forever loop. Here, I instead placed a set all pixel to red in the forever loop. This means that the CPX will be red when nothing elicits a response. On the other hand, I used another input “on button click A.” I attached my while true loop into the the input for “on button click A.” As a result, if I press the the “button A” on my CPX then the sound level and light level will respond if their values are true in respect to their logic comparison function. To recap, a loop function is another condition that evaluates a boolean function. The condition is tested before any code runs. This is important because if the condition is false, then the code inside the loop will not run. I hope this helps short chapter helps to understand the “while true” loop function.