From 917fb61e7d1d19ef434b64a76a0e3ba195e6e85e Mon Sep 17 00:00:00 2001 From: Frank DeMarco Date: Wed, 1 Aug 2018 20:08:25 -0400 Subject: [PATCH] bidirectional --- resource/scores | 1 + serial/serial.ino | 94 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/resource/scores b/resource/scores index c236b0a..c281cda 100644 --- a/resource/scores +++ b/resource/scores @@ -9,3 +9,4 @@ 5999999 5999999 293967 +283074 diff --git a/serial/serial.ino b/serial/serial.ino index 03506fc..496d790 100644 --- a/serial/serial.ino +++ b/serial/serial.ino @@ -1,17 +1,21 @@ // Generally, you should use "unsigned long" for variables that hold time // The value will quickly become too large for an int to store -unsigned long previousMillis = 0; // will store last time LED was updated +unsigned long previousMillis = 0; // will store last time LED was updated // constants won't change: -const long interval = 500; // interval at which to blink (milliseconds) +const long interval = 500; // interval at which to blink (milliseconds) int pushButton1 = 2; int pushButton2 = 4; int pushButton3 = 6; int pushButton4 = 11; -int buttons[4] = {pushButton1, pushButton2, pushButton3, pushButton4}; - +int buttons[4] = { + pushButton1, + pushButton2, + pushButton3, + pushButton4 +}; void setup() { // set the digital pin as output: @@ -23,8 +27,72 @@ void setup() { pinMode(pushButton4, INPUT_PULLUP); } -void loop() { - bool received_input = false; +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 { +// digitalWrite(buttons[i], HIGH); + pinMode(buttons[i], INPUT_PULLUP); + } + } +// delay(10); + + if (!digitalRead(buttons[B])) { + return true; + } else { + return false; + } +} +bool testConnection(int A, int B) { + return testConnection2(A, B) && testConnection2(B, A); +} + +// int lastNumber = -1; + +void loop() { + + if (testConnection(0, 1)) { +// if (lastNumber != 01) { +// lastNumber = 01; + Serial.println("0011"); +// } + } else if (testConnection(0, 2)) { +// if (lastNumber != 02) { +// lastNumber = 02; + Serial.println("0101"); +// } + } else if (testConnection(0, 3)) { +// if (lastNumber != 03) { +// lastNumber = 03; + Serial.println("1001"); +// } + } else if (testConnection(1, 2)) { +// if (lastNumber != 12) { +// lastNumber = 12; + Serial.println("0110"); +// } + } else if (testConnection(1, 3)) { +// if (lastNumber != 13) { +// lastNumber = 13; + Serial.println("1010"); +// } + } else if (testConnection(2, 3)) { +// if (lastNumber != 23) { +// lastNumber = 23; + Serial.println("1100"); +// } +// } else { +// if (lastNumber != 0) { +// lastNumber = 0; +// Serial.println("0000"); +// } + } +} + +/* + for (int ii = 0; ii < 4; ii++) { for (int jj = 0; jj < 4; jj++) @@ -58,10 +126,12 @@ void loop() { received_input = true; break; } - } - if (received_input) - { - break; - } + } + + + // if (received_input) + // { + // break; + // } } -} + */