Project 4: Colored Light - Thames & Kosmos Code Gamer Experiment Manual

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

PROJECT 4
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
THE PROGRAM
Here's something new to you. The
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!
Up to now, you have only learned about variables that act
as containers for numerical values. The
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
More specifically, rather than just having one value, they
can bring their own functions with them. These are also
known as methods. Your
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
,
green
red
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.
18
CodeGamer manual inside english.indd 18
instruction
#include
variable
pixel
.
int
pixel
, for example, is an object
,
, and
.
brightness
blue
little project will show you how it works, and how to get
your NeoPixel to shine in all sort of colors
#include <Adafruit_NeoPixel.h>
#include <KosmoBits_Pixel.h>
KosmoBits_Pixel pixel;
int red = 0;
int green = 0;
int blue = 0;
int brightness = 0;
Multicolored NeoPixel LED
</>
7/19/16 12:31 PM

Advertisement

Table of Contents
loading

Table of Contents