X
Y
Z
THE PROGRAM
Finger disco
YOU WILL NEED
› KosmoDuino in the interaction board
› Motion sensor
PREPARATION
With the motion sensor, your KosmoDuino will be able to
record even the tiniest movements. To develop the proper
feel for it, start by inserting the motion sensor into the
interaction board. Then upload the “ReadSensor” sketch to
your KosmoDuino.
You will now be able to observe the motion sensor’s readings
in the serial monitor. As long as you do not move the
controller, the reading will just fluctuate slightly around an
average value.
Now try moving the controller in different directions and
rotating and tipping it. You will see how there are
movement and rotation directions that cause the reading
to change sharply. In other directions the reading may
hardly change at all.
Now try drumming gently, and then somewhat more
strongly with your fingers on the interaction board housing.
Start by linking to the required libraries via the
#include
instructions, defining the
sensorPin
to be able to read
the sensor readings, and defining the
pixel
in order to be
able to control the NeoPixel.
To be able to recognize deviations from a resting state, you
still have to define the
restingValue
variable. The
resting average will be saved there.
#include <Adafruit_NeoPixel.h>
#include <KosmoBits_Pins.h>
#include <KosmoBits_Pixel.h>
const int sensorPin = KOSMOBITS_SENSOR_PIN;
KosmoBits_Pixel pixel;
int restingValue = 0;
In fact, the sensor merely measures the sensor’s
acceleration along the so-called z-axis, or the “forward-
and-backward axis.” That’s why the reading changes
when you move the controller away from you or back
towards you. Up-and-down movements, on the other
hand, will not change the reading.
▲
Fingers drum on the board and the NeoPixel blinks.
Even though the shaking caused by your fingers is very
slight, it is registered by the sensor. If you place the
controller on a table, you can even trigger the sensor by
just drumming on the table.
We can make use of this to turn your KosmoDuino into a
finger-drumming disco lighting device. To do that, use the
following program:
THE PLAN
Bright lights dancing in rhythm to your fingers. With this
project, you will be able to turn your KosmoDuino into a
Finger Disco.
36
PROJECT 9
CodeGamer manual inside english.indd 36
7/19/16 12:32 PM