Figure 13—Our binary die now has a guess button.
BinaryDice/DiceGame/DiceGame.ino
#include <Bounce2.h>
Line 1
const unsigned int LED_BIT0 = 12;
-
const unsigned int LED_BIT1 = 11;
-
const unsigned int LED_BIT2 = 10;
-
const unsigned int GUESS_BUTTON_PIN = 5;
5
const unsigned int START_BUTTON_PIN = 7;
-
const unsigned int BAUD_RATE = 9600;
-
const unsigned int DEBOUNCE_DELAY = 20;
-
-
int guess = 0;
10
Bounce start_button;
-
Bounce guess_button;
-
-
void setup() {
-
pinMode(LED_BIT0, OUTPUT);
15
pinMode(LED_BIT1, OUTPUT);
-
pinMode(LED_BIT2, OUTPUT);
-
pinMode(START_BUTTON_PIN, INPUT);
-
pinMode(GUESS_BUTTON_PIN, INPUT);
-
start_button.attach(START_BUTTON_PIN);
20
start_button.interval(DEBOUNCE_DELAY);
-
guess_button.attach(GUESS_BUTTON_PIN);
-
guess_button.interval(DEBOUNCE_DELAY);
-
randomSeed(analogRead(A0));
-
Serial.begin(BAUD_RATE);
25
}
-
-
Chapter 3. Building Binary Dice • 56
report erratum • discuss
www.it-ebooks.info