EasyManua.ls Logo

Thames & Kosmos Code Gamer - WAIT_UNTIL_DARK Mode

Thames & Kosmos Code Gamer
66 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
void setup() {
pinMode(sensorPin, INPUT);
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
Serial.begin(115200);
reset();
}
void loop() {
sw itch(m o de) {
case IDLE:
loopIdle();
break;
case COUNTDOWN:
loopCountdown();
break;
case WAIT_UNTIL_DARK:
l o o p U n t il D a r k ();
break;
case CLOSED:
loopClosed();
break;
case OPEN:
loopOpen();
break;
}
}
</>
In
s e tu p()
as usual, we determine the operating modes
of the pins being used and initialize the output through the
serial interface. Then,
r e s e t()
is invoked to return the
drawer monitor to its starting state.
In the main loop, depending on operating mode, different
loop functions may be invoked. The
sw itch(m o d e)
instruction handles that, introducing a case
differentiation. For each case, or possible
mode
value, a
different function is invoked:
If
mode
has the value
IDLE
,
loopIdle()
is invoked.
If
mode
has the value
COUNTDOWN
,
loopCountdown()
is invoked, etc.
The
break;
instruction is important here for breaking off
the treatment of a case and ending the case
differentiation. Without the
break;
instruction, the code
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.
Board with light sensor

PROJECT 17
CodeGamer manual inside english.indd 50 7/19/16 12:33 PM