int pin_A[4] = {2,3,4,5};
int pinVal_A[4] = {0,0,0,0};
int pin_B[4] = {6,7,8,9};
int pinVal_B[4] = {0,0,0,0};
int pin_C0 = 10;
int pinVal_C0 = 0;
void setup() {
Serial.begin(115200);
for(int i = 0; i <= 3; i++) {
pinMode(pin_A[i], OUTPUT);
pinMode(pin_B[i], OUTPUT);
}
for(int i = 0; i <= 3; i++) {
digitalWrite(pin_A[i], pinVal_A[i]);
digitalWrite(pin_B[i], pinVal_B[i]);
}
pinMode(pin_C0, OUTPUT);
digitalWrite(pin_C0, pinVal_C0);
}
void loop() {
uint8_t aVal = random(0, 16);
uint8_t bVal = random(0, 16);
for (int i = 0; i < 4; ++i) {
digitalWrite(pin_A[i], aVal >> i & 1);
}
for (int i = 0; i < 4; ++i) {
digitalWrite(pin_B[i], bVal >> i & 1);
}
uint8_t cVal = random(0, 2);
digitalWrite(pin_C0, cVal);
uint16_t result = aVal + bVal + cVal;
Serial.print(aVal);
Serial.print(" + ");
Serial.print(bVal);
Serial.print(" + ");
Serial.print(cVal);
Serial.print(" = ");
Serial.println(result);
delay(5000);
}