// by Dr. Clement Shimizu for Scrapeboard // constants won't change: const long interval = 25; // 25 ms * 6 tests * 2 = 200 ms means 5 loops per second /* * Each pin corresponds with a panel on the platform and should be physically connected by a wire to the metal plate on the panel, * with a 4.7k resistor in the connection. * * +--------------+--------------+ * | Arduino Pin | Panel Color | * +-------------+--------------+--------------+ * | pushButton1 | Arduino PIN2 | Yellow Panel | * | pushButton2 | Arduino PIN3 | Pink Panel | * | pushButton3 | Arduino PIN4 | Blue Panel | * | pushButton4 | Arduino PIN5 | Red Panel | * +-------------+--------------+--------------+ */ int pushButton1 = 2; int pushButton2 = 3; int pushButton3 = 4; int pushButton4 = 5; int buttons[4] = { pushButton1, pushButton2, pushButton3, pushButton4 }; void setup() { // set the digital pin as output: Serial.begin(9600); pinMode(pushButton1, OUTPUT); digitalWrite(pushButton1, LOW); pinMode(pushButton2, INPUT_PULLUP); pinMode(pushButton3, INPUT_PULLUP); pinMode(pushButton4, INPUT_PULLUP); } bool testConnection2(int A, int B) { for (int i = 0; i < 4; i++) { if (i == A) { pinMode(buttons[i], OUTPUT); digitalWrite(buttons[i], LOW); } else { pinMode(buttons[i], INPUT_PULLUP); } } delay(interval); if (!digitalRead(buttons[B])) { return true; } else { return false; } } bool testConnection(int A, int B) { return testConnection2(A, B) && testConnection2(B, A); } void loop() { if (testConnection(0, 1)) { Serial.println("0011"); } else if (testConnection(0, 2)) { Serial.println("0101"); } else if (testConnection(0, 3)) { Serial.println("1001"); } else if (testConnection(1, 2)) { Serial.println("0110"); } else if (testConnection(1, 3)) { Serial.println("1010"); } else if (testConnection(2, 3)) { Serial.println("1100"); } }