Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created September 23, 2012 23:20
Show Gist options
  • Select an option

  • Save ngerakines/3773403 to your computer and use it in GitHub Desktop.

Select an option

Save ngerakines/3773403 to your computer and use it in GitHub Desktop.
led dice with button
const unsigned int LED_BIT0 = 12;
const unsigned int LED_BIT1 = 11;
const unsigned int LED_BIT2 = 10;
const unsigned int SWITCH_BIT = 9;
void setup() {
pinMode(LED_BIT0, OUTPUT);
pinMode(LED_BIT1, OUTPUT);
pinMode(LED_BIT2, OUTPUT);
pinMode(SWITCH_BIT, INPUT);
randomSeed(analogRead(A0));
}
void loop() {
//read button state
if(digitalRead(SWITCH_BIT) != HIGH){
roll();
delay(200);
}
}
void roll(){
long result = random(1,7);
output_result(result);
}
void output_result(const long result) {
digitalWrite(LED_BIT0, result & B001);
digitalWrite(LED_BIT1, result & B010);
digitalWrite(LED_BIT2, result & B100);
}
void clear_result(){
digitalWrite(LED_BIT0, LOW);
digitalWrite(LED_BIT1, LOW);
digitalWrite(LED_BIT2, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment