const int binaryPins[] = {10, 11, 12, 13};
const int addPins[] = {6, 7, 8, 9};
const int resultPins[] = {1, 2, 3, 4, 5};
int carrypin = 0;
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(binaryPins[i], INPUT_PULLUP);
pinMode(addPins[i], INPUT_PULLUP);
pinMode(resultPins[i], OUTPUT);
}
pinMode(resultPins[4], OUTPUT);
pinMode(carrypin,INPUT_PULLUP);
}
void loop() {
bool carry = !digitalRead(carrypin);
for (int i = 0; i < 4; i++) {
bool a = digitalRead(binaryPins[i]) == LOW;
bool b = digitalRead(addPins[i]) == LOW;
bool c = a != b;
bool s = c != carry;
carry = a && b || c && carry;
digitalWrite(resultPins[i], s ? LOW : HIGH);
}
digitalWrite(resultPins[4], carry ? LOW : HIGH);
}