Project – cat toy
In this project, we'll add a piece of paper to our motor, and then code some randomness to make it spin back and forth at varying speeds (cats get bored with a predictable toy, after all).
The wiring for this project is the same as the motor test; no need to change anything there.
Putting a piece of paper on the motor shaft
Either roll the sticky end of a long sticky note around the motor shaft, or tape a long strip of paper to it. It should look something like this:

After the relatively simple construction of our toy, let's code some randomness!
Coding the randomness to start/stop the motor
We want the motor to start at a random speed for anywhere from 1-10 seconds, then stop for 1-10 seconds, and repeat. We also want whether it goes forward or backward to be random. I limited the speed to 75—anything faster was too much for my cats!
In your cat-toy.js
file, get rid of the board.repl.inject
statement and add the following:
startMovement() functionstartMovement(){ letdirection...