EasyManuals Logo

Arduino uno User Manual

Arduino uno
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

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals