Hardware Reference
In-Depth Information
Listing 11-1. Stop It's Code, Part 6 of 11
void flashWin() {
delay (100);
LEDshift = 0xFAAA;
for ( int i = 0 ; i < 10; i++) {
LEDshift = ~LEDshift;
displayLED();
delay (100);
}
} // end flashWin
The BigWin() function of part 7 is called when the player makes 11 successful wins. This function first calls the
flashWin() function and then loads a new pattern, starting from the center LED and radiating outward, turning on all
the LEDs. The function does this four times before finishing up with another flashWin() .
Listing 11-1. Stop It's Code, Part 7 of 11
void BigWin () {
flashWin();
for (int i = 0 ; i < 4 ; i++) {
LEDshift = 0x0040; // turn on the center LED
displayLED();
delay (100);
for (int i = 0 ; i < 6 ; i++) {
LEDshift = LEDshift | (1<< 5 - i); // radiate from the center by a logical OR of the 1s
// into the
LEDshift = LEDshift | (1<< 7 + i); // LEDshift variable
displayLED();
delay (25);
}
}
flashWin();
} // end BigWin
Every game has to have a condition for not winning. Part 8 of Listing 11-1 is the notWin() function. The notWin()
function resets the level back to zero and sweeps the LED from right to left. The loop to display the pattern shifts the
LEDshift variable to the left by 1, and then increments the variable till the loop is finished.
Listing 11-1. Stop It's Code, Part 8 of 11
void notWin() {
level = 0;
delay (100);
LEDshift = 0x0001;
for ( int i = 0 ; i < 11; i++) {
LEDshift = LEDshift << 1;
LEDshift++;
displayLED();
delay (100);
}
} // end notWin
 
Search WWH ::




Custom Search