You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/arduino/DiceWithButton/DiceWithButton.ino

33 lines
737 B

const unsigned int LED_BIT0 = 10;
const unsigned int LED_BIT1 = 11;
const unsigned int LED_BIT2 = 12;
const unsigned int BUTTON_PIN = 7;
int currentValue = 0;
int oldValue = 0;
void outputResult(const long result) {
digitalWrite(LED_BIT0, result & B001);
digitalWrite(LED_BIT1, result & B010);
digitalWrite(LED_BIT2, result & B100);
}
void setup() {
pinMode(LED_BIT0, OUTPUT);
pinMode(LED_BIT1, OUTPUT);
pinMode(LED_BIT2, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
randomSeed(analogRead(A0));
}
void loop() {
currentValue = digitalRead(BUTTON_PIN);
if (currentValue != oldValue && currentValue == HIGH) {
outputResult(random(1, 7));
delay(50);
}
oldValue = currentValue;
}