byte digits[] = {0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b,0x77, 0x1f, 0x4e, 0x3d, 0x4f, 0x47};
int inputPin[] = {2, 3, 4, 5, 6, 7, 8, 9};
int dataPin = 10;
int clockPin = 11;
int latchPin = 12;
int switchPin = 13;
int sum = 0;
void setup() {
// put your setup code here, to run once:
for(int x = 0; x < 8; x++){
pinMode(inputPin[x], INPUT);
}
pinMode(switchPin, INPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int bit0 = digitalRead(inputPin[0]) * 1;
int bit1 = digitalRead(inputPin[1]) * 2;
int bit2 = digitalRead(inputPin[2]) * 4;
int bit3 = digitalRead(inputPin[3]) * 8;
int bit4 = digitalRead(inputPin[4]) * 16;
int bit5 = digitalRead(inputPin[5]) * 32;
int bit6 = digitalRead(inputPin[6]) * 64;
int bit7 = digitalRead(inputPin[7]) * 128;
sum = bit0 + bit1 + bit2 + bit3 + bit4 + bit5 + bit6 + bit7;
if(digitalRead(switchPin) == LOW){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[sum % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(sum/10) % 10]);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(sum/100) % 10]);
digitalWrite(latchPin, HIGH);
delay(100);
}
if(digitalRead(switchPin) == HIGH){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digits[sum % 16]);
shiftOut(dataPin, clockPin, MSBFIRST, digits[(sum/16) % 16]);
shiftOut(dataPin, clockPin, MSBFIRST, 0x00);
digitalWrite(latchPin, HIGH);
delay(100);
}
}