Project 5: At The Push Of A Button - Thames & Kosmos Code Gamer Experiment Manual

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

PROJECT 5
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
▲ Finger pushes right button — NeoPixel glows red
▲ Finger pushes left button — NeoPixel glows blue
Here, you are defining two constants for the pins to which
the two interaction board buttons are connected. These
are abbreviated as
const
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.
22
CodeGamer manual inside english.indd 22
. This keyword communicates to
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
#include <Adafruit_NeoPixel.h>
#include <KosmoBits_Pixel.h>
#include <KosmoBits_Pins.h>
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.
▲ Two fingers push both buttons simultaneously — NeoPixel glows purple
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;
7/19/16 12:32 PM

Advertisement

Table of Contents
loading

Table of Contents