/* * This code will drive a three input circuit. */ // Constants for pin identification const int A_PIN{3}; const int B_PIN{4}; const int C_PIN{5}; const int RES_PIN{6}; void setup() { // set up the serial communications data rate Serial.begin(9600); // set the pins for the right mode. pinMode(A_PIN, OUTPUT); pinMode(B_PIN, OUTPUT); pinMode(C_PIN, OUTPUT); pinMode(RES_PIN, INPUT); } // this could be static loop, but. int i{0}; void loop() { // mark the top of the loo if (i == 0) { Serial.println("\n"); Serial.println("Top of Loop"); } // extract the values from the state. int a = (i & 4) >>2; int b = (i & 2) > 1; int c = i & 1; // print the state Serial.print(" i = "); Serial.print(i); Serial.print(" a = "); Serial.print(a); Serial.print(" b = "); Serial.print(b); Serial.print(" c = "); Serial.print(c); Serial.print(" "); // write the state to the chips digitalWrite(A_PIN, a); digitalWrite(B_PIN, b); digitalWrite(C_PIN, c); // wait a bit and read the state delay(100); int pinState = digitalRead(RES_PIN); // and print the result Serial.print(" result is "); Serial.println(pinState); // increment the state i = (i + 1) % 8; // wait for some time delay(2000); // turn the output led off. digitalWrite(A_PIN, 0); digitalWrite(B_PIN, 0); digitalWrite(C_PIN, 0); delay(500); }