/*
Dette array med 10 tal plus 'clear display' viser status for
de segmenter, der skal vise det givne tal. Dette bruges til at
simplificere koden senere - vi kan indeksere arrayet for at
vise det rigtige tal.
*/
const bool TAL [11][7]
{{1,1,1,1,1,1,0}, // nul
{0,1,1,0,0,0,0}, // et
{1,1,0,1,1,0,1}, // to
{1,1,1,1,0,0,1}, // tre
{0,1,1,0,0,1,1}, // fire
{1,0,1,1,0,1,1}, // fem
{1,0,1,1,1,1,1}, // seks
{1,1,1,0,0,0,0}, // syv
{1,1,1,1,1,1,1}, // otte
{1,1,1,0,0,1,1}, // ni
{0,0,0,0,0,0,0}};// Clear display
const int CLEAR_DISPLAY {10};
const int BIT1 {14};
const int BIT2 {15};
const int BIT3 {16};
const int KNAP1 {17};
const int KNAP2 {18};
const int KNAP3 {19};
bool bit[3] {0, 0, 0};
void setup() {
for (int i = 2; i <= 16; i++) pinMode(i, OUTPUT);
for (int i = 17; i <= 19; i++) pinMode(i, INPUT_PULLUP);
for (int i = BIT1; i <= BIT3; i++) {
digitalWrite(i, LOW);
bit[i - 14] = 0;
}
}
// denne funktion goer det aktuelle arbejde med 7-segmentes pins.
void displayTal(int talTilVisning) {
int pin {2};
for (int segment = 0; segment <= 6; segment++) {
digitalWrite(pin, TAL[talTilVisning][segment]);
pin++;
}
}
void loop() {
for (int i = KNAP1; i <= KNAP3; i++) {
if (!digitalRead(i)) bit[i - 17] = !bit[i - 17];
digitalWrite(i - 3, bit[i - 17]);
delay(100);
}
int tal = bit[2]*4 + bit[1]*2 + bit[0];
displayTal(tal);
}