Thames & Kosmos Code Gamer Experiment Manual page 25

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

In
setup()
, you use
pinMode()
mode for the button pins. Since the buttons are connected
to the pins via a resistor, you will use the
operating type.
In the first
instruction
if
out the pin to which button 1 is connected. When the
button is pressed, it yields the value
i.e., the largest possible value, is assigned to
If the button is not pressed,
The entire sequence is repeated for button 2 in the second
instruction. The only difference is that the value for
if
is given.
blue
Finally,
pixel.setColor(red, green, blue, brightness);
sets the new color value for the NeoPixel.
At the end of the main loop, you make the controller wait
another 50 milliseconds.
WHAT ACTUALLY HAPPENS WHEN YOU UPLOAD SOMETHING?
When you upload a program to your KosmoDuino, actually, a whole lot of things happen. The microcontroller does not
really understand the program as you have written it. It simply doesn't speak the programming language. That's why
the program first has to be translated into machine language. That is something handled by a so-called compiler.
The programming language that you use, in other words, is just an intermediate language that is not only easy for you to
understand and write, but most important of all, is one that the compiler can easily translate into machine language.
CodeGamer manual inside english.indd 23
to set the operating
INPUT
digitalRead()
is used to read
: The value
LOW
255
.
red
is set to
.
red
0
void setup() {
pinMode(button1, INPUT);
pinMode(button2, INPUT);
}
void loop() {
,
if (digitalRead(button1) == LOW) {
red = 255;
} else {
red = 0;
}
if (digitalRead(button2) == LOW) {
blue = 255;
} else {
blue = 0;
}
pixel.setColor(red, green, blue, brightness);
delay(50);
}
CodeGamer
</>
!
23
7/19/16 12:32 PM

Advertisement

Table of Contents
loading

Table of Contents