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 #73 background imageLoading...
Page #73 background image
Figure 12Our binary die with its own start button
int current_value = 0;
int old_value = 0;
void loop() {
current_value = digitalRead(BUTTON_PIN);
if (current_value != old_value && current_value == HIGH) {
output_result(random(1, 7));
delay(50);
}
old_value = current_value;
}
void output_result(const long result) {
digitalWrite(LED_BIT0, result & B001);
digitalWrite(LED_BIT1, result & B010);
digitalWrite(LED_BIT2, result & B100);
}
Thats a perfect merge of the original code and the code needed to control a
debounced button. As usual, we initialize all pins we use: three output pins
for the LEDs and one input pin for the button. We also initialize the random
seed, and in the
loop
function we wait for new button presses. Whenever the
button gets pressed, we roll the die and output the result using the LEDs.
Weve replaced the reset button with our own!
Now that you know how easy it is to add a pushbutton, well add another one
in the next section to turn our simple die into a game.
Chapter 3. Building Binary Dice 54
report erratum discuss
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