Thames & Kosmos Code Gamer Experiment Manual page 52

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

PROJECT 17
In
setup()
as usual, we determine the operating modes
of the pins being used and initialize the output through the
serial interface. Then,
drawer monitor to its starting state.
In the main loop, depending on operating mode, different
loop functions may be invoked. The
instruction handles that, introducing a case
differentiation. For each case, or possible
different function is invoked:
• If
has the value
mode
• If
has the value
mode
is invoked, etc.
The
break;
instruction is important here for breaking off
the treatment of a case and ending the case
differentiation. Without the
for the next case would also be carried out.
That ends the basic skeleton of our program. Now we will
just have to think about what exactly we want the drawer
monitor to do in its various operating modes.
50
CodeGamer manual inside english.indd 50
is invoked to return the
reset()
switch(mode)
value, a
mode
,
loopIdle()
is invoked.
IDLE
,
loopCountdown()
COUNTDOWN
break;
instruction, the code
void setup() {
pinMode(sensorPin, INPUT);
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
Serial.begin(115200);
reset();
}
void loop() {
switch(mode) {
case IDLE:
loopIdle();
break;
case COUNTDOWN:
loopCountdown();
break;
case WAIT_UNTIL_DARK:
loopUntilDark();
break;
case CLOSED:
loopClosed();
break;
case OPEN:
loopOpen();
break;
}
}
</>
◀ Board with light sensor
7/19/16 12:33 PM

Advertisement

Table of Contents
loading

Table of Contents