The code seen below is the final iteration of the code used in the project. In order to skip repetition, the parts of the code that are more or less the same have been left. The link to the entire program is at the bottom of the page.
Take the time to read the comments, as they describe how the code itself works, where as the description just says what the code does.
Everything is in order that it appears in the code.
Initialize variables that will be used later in the code and include the code library for Arduino IoT Cloud.
Setup runs before everything else, it initializes what pin each of the parts hardware components are attached to. Since the LEDs are wired in series, there is only one command that controls all of the LEDs.
This is the first part of the loop. The code here runs before everything else in the loop. To begin, the force sensor values are assigned to different variables to be used later. The code after that is a simple trick to treat a button as a switch, which switches between the two lightpacks (which change what colors the lights turn to on each key).
This code is the initial and example of how different pressures result in different colors and how the code checks which light pack has been selected.
This code simply changes the values of the aggro variable for the IoT cloud to display how hard the children are hitting the keys.
Code that finds the force applied to the force sensor. As said in the comment, code was used from link above.
Code that changes the colors of the LEDs.
The original plan for the project was to make the xylophone make different animal sounds, but after much research and consulting professional help, I learned that it would be impossible to have it make sound without purchasing new stuff, which would have put us very far behind schedule.
As such, all the time I had spent trying to figure out how to make the sound work with our current hardware became worthless. I estimated 80% of the total time I spent working on the code was dedicated to making the speakers work.
Thankfully, our classmate, Tori, had RBG LEDs available for us to use in our project. Our electronics professional, Katie, quickly wired the LEDs up and I switched over all of the code from trying to make the speaker work, to lighting up our new LEDs.
In the end, the code worked exactly as I planned it to, without any recurring bugs or glitches.