The code presented on this page can be downloaded or found in the Arduino examples menu under Examples → SpinWearables → Stroboscope
.
As seen in the SpinWheel stroboscope adventure
#include "SpinWearables.h"
using namespace SpinWearables;
First we would like to ensure the brightness is set to maximum, as we are not going to use the LEDs for aesthetics, but rather as a source of illumination.
void setup() {
.begin();
SpinWheel.setBrightness(255);
SpinWheel}
We will set the default period to 10 milliseconds and let it vary from 8 milliseconds to 12 milliseconds.
long default_delay_time = 10000;
long max_correction = 2000;
And now we have the main body of the program, which will turn the light on and then off rapidly.
void loop() {
We first read the tilt of the device and use it to modify the default period.
.readIMU();
SpinWheellong delaytime = default_delay_time + SpinWheel.ax * max_correction;
Set the lights on.
.setLargeLEDsUniform(255, 255, 255);
SpinWheel.drawLargeLEDFrame(); SpinWheel
Wait only a small fraction of the total period (3% in this case).
(0.03*delaytime); delayMicroseconds
Then turn the lights off and wait for the rest of the time.
.setLargeLEDsUniform(0, 0, 0);
SpinWheel.drawLargeLEDFrame();
SpinWheel(0.97*delaytime);
delayMicroseconds}
Notice we used drawLargeLEDFrame()
instead of drawFrame()
. We did so because drawFrame
also sets the small LEDs, which used a much slower persistence-of-vision pattern and can not work at more than 50 frames per second.