![Thames & Kosmos Code Gamer Скачать руководство пользователя страница 20](http://html1.mh-extra.com/html/thames-and-kosmos/code-gamer/code-gamer_experiment-manual_1099224020.webp)
Colored light
YOU WILL NEED
› KosmoDuino in the interaction board
THE PLAN
On the interaction board, you will find a multicolored LED
called a NeoPixel. It’s a kind of LED that lets you decide
what color and brightness level you want it to have. This
Up to now, you have only learned about variables that act
as containers for numerical values. The
pixel
variable
that you are defining here is a little different: Instead of
numbers, it serves as a container for an
object of the
KosmoBits_Pixel type. That sounds more confusing than it
really is. It just means that objects can be more than
simple values such as
int
.
More specifically, rather than just having one value, they
can bring their own functions with them. These are also
known as
methods. Your
pixel
, for example, is an object
that you can use to control the NeoPixel on your
interaction board. For that purpose, it has a method by the
name of
setColor()
, that you can use to adjust the color
and brightness of the NeoPixel. Next, in the main loop, you
will learn how this works.
To adjust the color and brightness of your NeoPixel, you
will need four number values — one for the brightness
and three for the primary colors red, green, and blue.
These values will be saved in the corresponding
variables
red
,
green
,
blue
, and
brightness
.
The various colors will be produced by mixing these three
basic colors. You will be setting the corresponding
number value to determine how strongly each of the
colors in this mixture will be represented. You can use
values from 0 to 255. 0 means that the corresponding
color will not light up at all. With a value of 255, the
color will shine with the highest possible brightness.
KosmoBits_Pixel pixel;
#include <Adafruit_NeoPixel.h>
#include <KosmoBits_Pixel.h>
int red = 0;
int green = 0;
int blue = 0;
int brightness = 0;
Here’s something new to you. The
#include
instruction
will let you include code from other programs in your
program. In this case, you will be including content from the
“Adafruit_NeoPixel.h” and “KosmoBits_Pixel.h” files.
You will always have to insert these two lines at the
beginning of your program when you want to use the
NeoPixel!
Multicolored NeoPixel LED
THE PROGRAM
little project will show you how it works, and how to get
your NeoPixel to shine in all sort of colors
</>
18
PROJECT 4
CodeGamer manual inside english.indd 18
7/19/16 12:31 PM