Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program for 7-Segment LED Die
- int segmentPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
- int displayPins[] = {10};
- int buttonPin = 11;
- byte digits[10][8] = {
- // a b c d e f g .
- { 1, 1, 1, 1, 1, 1, 0, 0}, // 0
- { 0, 1, 1, 0, 0, 0, 0, 0}, // 1
- { 1, 1, 0, 1, 1, 0, 1, 0}, // 2
- { 1, 1, 1, 1, 0, 0, 1, 0}, // 3
- { 0, 1, 1, 0, 0, 1, 1, 0}, // 4
- { 1, 0, 1, 1, 0, 1, 1, 0}, // 5
- { 1, 0, 1, 1, 1, 1, 1, 0}, // 6
- { 1, 1, 1, 0, 0, 0, 0, 0}, // 7
- { 1, 1, 1, 1, 1, 1, 1, 0}, // 8
- { 1, 1, 1, 1, 0, 1, 1, 0} // 9
- };
- void setup()
- {
- for (int i=0; i < 8; i++)
- {
- pinMode(segmentPins[i], OUTPUT);
- }
- pinMode(displayPins[0], OUTPUT);
- pinMode(displayPins[0], OUTPUT);
- pinMode(buttonPin, INPUT);
- }
- void loop()
- {
- static int dice;
- if (digitalRead(buttonPin))
- {
- dice = random(1,7);
- }
- updateDisplay(dice);
- }
- void updateDisplay(int value1)
- {
- digitalWrite(displayPins[0], HIGH);
- digitalWrite(displayPins[1], LOW);
- setSegments(value1);
- delay(5);
- digitalWrite(displayPins[0], LOW);
- digitalWrite(displayPins[1], HIGH);
- delay(5);
- }
- void setSegments(int n)
- {
- for (int i=0; i < 8; i++)
- {
- digitalWrite(segmentPins[i], ! digits[n][i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement