jannetta.com

My mind is like an Internet browser. At least 19 tabs open, three are frozen and I have no clue where the music is coming from.

When I'm stressed I Build Things

Aruidno Dice

Some people go for a walk, some people to to the pub but when I’m stressed I build things. My son and I like playing board games but those dice always go rolling all over the place. To solve the problem and to “de-stress” myself I built and Arduino dice. There are loads of circuits around on the Internet and in books, but I just made my own so that I can concentrate on it and forget about the world around me.

This version uses a seven segment LED display and seven Arduino pins. It also uses a button which uses another one of the Arduino pins. Each of the LED segments is connected to an Arduino pin via a 470 ohm resistor. The button uses a 10KOhm pull down resistor to keep the pin low and when the button is pressed the pin goes high. While the pin is high the Arduino program will generate random numbers and when the button is released the last number generated is used.

Below is the code and a small video for the dice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#define A 11
#define B 10
#define C 6
#define D 3
#define E 2
#define F1 12
#define G 13
#define H 6
#define SEGMENTS 7

const int buttonPin = 8;
int buttonState = 0;
const int delaid = 400;
char zero[SEGMENTS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW};
char one[SEGMENTS] = {LOW, HIGH, HIGH, LOW, LOW, LOW, LOW};
char two[SEGMENTS] = {HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH};
char three[SEGMENTS] = {HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH};
char four[SEGMENTS] = {LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH};
char five[SEGMENTS] = {HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH};
char six[SEGMENTS] = {HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH};
char seven[SEGMENTS] = {HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW};
char eight[SEGMENTS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
char nine[SEGMENTS] = {HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH};
int seed;
int num = 0;

void setup() {
	Serial.begin(9600);
	pinMode(A, OUTPUT);
	pinMode(B, OUTPUT);
	pinMode(C, OUTPUT);
	pinMode(D, OUTPUT);
	pinMode(E, OUTPUT);
	pinMode(F1, OUTPUT);
	pinMode(G, OUTPUT);
	pinMode(H, OUTPUT);
	pinMode(buttonPin, INPUT);
	randomSeed(analogRead(0));

	Serial.println(num);
}

void loop() {
	buttonState = digitalRead(buttonPin);
	if (buttonState == HIGH) {
		num = random(1, 7);
	} else {
		switch (num) {
		case 1:
			disp(one);
			break;
		case 2:
			disp(two);
			break;
		case 3:
			disp(three);
			break;
		case 4:
			disp(four);
			break;
		case 5:
			disp(five);
			break;
		case 6:
			disp(six);
			break;
		}
	}

}

 

void disp(char segment[]) {
	digitalWrite(A, segment[0]);
	digitalWrite(B, segment[1]);
	digitalWrite(C, segment[2]);
	digitalWrite(D, segment[3]);
	digitalWrite(E, segment[4]);
	digitalWrite(F1, segment[5]);
	digitalWrite(G, segment[6]);
}