Background
The Circuit Playground Express (CPE) has a built in accelerometer. I used it to count how many punches or curls with a weight. MakeCode triggers an event when the strength of the three axis accelerometer crosses a threshold.
For every punch, I wanted to a new neopixel to light up. When I reached the max number of reps in a set, I wanted a different light color to track how many sets I had completed. When I finished 10 sets, I wanted the to be an audible alert and the lights to reset.
Build
I just taped the CPE to the upper part of the glove and the battery to the bottom of the glove.
Code
https://makecode.com/_PvChHzdPmdgb
When the program starts, the counters for punch and set were specified to zero. The reps were defined as 5 reps in one set. You can pick a number from 0 to 10 for reps. The limit is 10 because there are 10 neopixels on the board.
The purple "on 3g" block is an event trigger. You can set it to 3g, 6g, or 8g. When I used 3g, it sometimes counted me pulling back my arm as a punch. When a punch triggers the event block, a neopixel is set to purple. The first punch sets the first pixel. The second punch sets the second pixel. The first pixel is still lit from the first punch. Then the punch count is incremented by 1.
If the number of punches is equal to the rep count, then the lights resets and the punch count is reset to zero. Red neopixels show the number of sets completed. The for loop lights red neopixles from 0 to the completed number of sets. The set tracker is increased by one after completing the for loop. These red lights are shown until the next punch.
If the number of sets is equal to 10, then we have completed our session. A siren sound will play letting us know that we are done. The punch and set counts will reset to zero and the lights will go off. Then we can start tracking from the beginning again if we want.
Comments