![Thames & Kosmos Code Gamer Скачать руководство пользователя страница 24](http://html1.mh-extra.com/html/thames-and-kosmos/code-gamer/code-gamer_experiment-manual_1099224024.webp)
At the push of a button
In this project, you will learn how to use the buttons on the
interaction board to make the NeoPixel light up in
different colors.
YOU WILL NEED
› KosmoDuino in the interaction board
THE PLAN
#include <Adafruit_NeoPixel.h>
#include <KosmoBits_Pixel.h>
#include <KosmoBits_Pins.h>
Here, you are defining two
constants for the pins to which
the two interaction board buttons are connected. These
are abbreviated as
const
. This keyword communicates to
the program that an object or a variable cannot be
changed.
As in the previous program, you are saving the various
color values and the brightness in corresponding
variables that you define here.
To be able to control the NeoPixel on the interaction
board, you once again need a KosmoBits_Pixel object.
You are defining that here.
const int button1 = KOSMOBITS_BUTTON_1_PIN;
const int button2 = KOSMOBITS_BUTTON_2_PIN;
int red = 0;
int green = 0;
int blue = 0;
const int brightness = 50;
KosmoBits_Pixel pixel;
First, we want the NeoPixel to stay dark. If you press
button 1, the NeoPixel will glow red, while if you press
button 2 it will glow blue. If you press both at the same
time, it glows purple.
THE PROGRAM
You learned in the last project how to link to libraries and
code from other files in a program. The new library here is
KosmoBits_Pins.h
. This defines names for the various
KosmoDuino pins used by the interaction board. We will
take a closer look at the KosmoBits libraries a little later
on in this manual.
▲
Finger pushes right button — NeoPixel glows red
▲
Finger pushes left button — NeoPixel glows blue
▲
Two fingers push both buttons simultaneously — NeoPixel glows purple
22
PROJECT 5
CodeGamer manual inside english.indd 22
7/19/16 12:32 PM