Boogie Ball: Code Snippet

The ball’s rotation is done through the implementation of a Timer Compare Interrupt. Each time this interrupt occurs, a global flag is set in the code. The main program loop checks this flag each loop and updates the servo position each time it is set. The flag is then cleared and the loop continues until the interrupt occurs again. A snippet of the code that changes the servo position is shown below along with a video of the spinning.

Each loop of the program also updates the LEDs. As previously explained, each of the 6 needed frequency bands is read by first toggling the RESET line once and then the STROBE line once for each of the 6 bands. Between each STROBE toggle, the MSGEQ7 input line is read and converted to an analog integer value between 0 and 1023. This value is then immediately mapped between 0 and 9 to determine how many of the LEDs will be turned on for each strip. A snippet of the code that updates the LEDs is show below along with a video demonstration its reaction to music.