EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #76 background imageLoading...
Page #76 background image
void loop() {
-
handle_guess_button();
-
handle_start_button();
30
}
-
-
void handle_guess_button() {
-
if (guess_button.update()) {
-
if (guess_button.read() == HIGH) {
35
guess = (guess % 6) + 1;
-
output_result(guess);
-
Serial.print("Guess: ");
-
Serial.println(guess);
-
}
40
}
-
}
-
-
void handle_start_button() {
-
if (start_button.update()) {
45
if (start_button.read() == HIGH) {
-
const int result = random(1, 7);
-
output_result(result);
-
Serial.print("Result: ");
-
Serial.println(result);
50
if (guess > 0) {
-
if (result == guess) {
-
Serial.println("You win!");
-
hooray();
-
} else {
55
Serial.println("You lose!");
-
}
-
}
-
delay(2000);
-
guess = 0;
60
}
-
}
-
}
-
void output_result(const long result) {
-
digitalWrite(LED_BIT0, result & B001);
65
digitalWrite(LED_BIT1, result & B010);
-
digitalWrite(LED_BIT2, result & B100);
-
}
-
-
void hooray() {
70
for (unsigned int i = 0; i < 3; i++) {
-
output_result(7);
-
delay(500);
-
output_result(0);
-
delay(500);
75
}
-
}
-
report erratum discuss
Building a Dice Game 57
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino Pro Mini and is the answer not in the manual?

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals