Thames & Kosmos Code Gamer Experiment Manual page 21

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

In
setup()
there will be nothing for you to do this time,
since the program that you will be linking with the
instruction will already be handling it for you.
#include
In the main loop, the first thing to do is set the brightness:
brightness = 50;
. The highest level of brightness is set
with a value of 255; with 0, the NeoPixel remains dark.
Then the various colors are produced one after the other.
To do that, you will be assigning the
variables different values.
blue
The line
pixel.setColor(red, green, blue, brightness);
the decisive factor for each color. First of all, it tells the
NeoPixel that it is supposed to display a new color! In
these instructions,
setColor()
the
pixel
object. To invoke a method of an object, the
method's name is attached to the name of the object
separated by a period.
With
delay(500);
you will make your KosmoDuino wait
half a second before adjusting the net color.
The NeoPixel
shines in
various colors ▶
CodeGamer manual inside english.indd 19
,
green
and
red
is
is a so-called method of
void setup() {
// There is nothing to do here.
}
void loop() {
// 50 is a good brightness value.
// The highest brightness level is 255.
// It can be a bit blinding though!
brightness = 50;
// red
red = 255;
green = 0;
blue = 0;
pixel.setColor(red, green, blue, brightness);
delay(500);
// green
red = 0;
green = 255;
blue = 0;
pixel.setColor(red, green, blue, brightness);
delay(500);
// blue
red = 0;
green = 0;
blue = 255;
pixel.setColor(red, green, blue, brightness);
delay(500);
// purple
red = 255;
green = 0;
blue = 255;
pixel.setColor(red, green, blue, brightness);
delay(500);
// turquoise
red = 0;
green = 255;
blue = 255;
pixel.setColor(red, green, blue, brightness);
delay(500);
// yellow
red = 255;
green = 255;
blue = 0;
pixel.setColor(red, green, blue, brightness);
delay(500);
CodeGamer
</>
19
7/19/16 12:32 PM

Advertisement

Table of Contents
loading

Table of Contents