This commit is contained in:
Frank DeMarco 2018-06-27 21:28:08 -04:00
parent 9e84a17b8d
commit 62e5e2e50b
1 changed files with 87 additions and 0 deletions

87
serial/serial.ino Normal file
View File

@ -0,0 +1,87 @@
// 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
// constants won't change:
const long interval = 500; // interval at which to blink (milliseconds)
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);
}
void loop() {
unsigned long currentMillis = millis();
bool received_input = false;
for (int ii = 0; ii < 4; ii++)
{
for (int jj = 0; jj < 4; jj++)
{
if (jj == ii)
{
pinMode(buttons[jj], OUTPUT);
digitalWrite(buttons[jj], LOW);
}
else
{
pinMode(buttons[jj], INPUT_PULLUP);
}
}
for (int jj = ii; jj < 4; jj++)
{
if (!(ii == jj) && !digitalRead(buttons[jj]))
{
for (int kk = 3; kk >= 0; kk--)
{
if (kk == ii || kk == jj)
{
Serial.print(1);
}
else
{
Serial.print(0);
}
}
Serial.print("\n");
received_input = true;
break;
}
}
if (received_input)
{
break;
}
}
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
//if(digitalRead(pushButton1)==0){
//}
//if(digitalRead(pushButton2)==0){
// Serial.println("1-2");
//}
//if(digitalRead(pushButton3)==0){
// Serial.println("1-3");
//}
//if(digitalRead(pushButton4)==0){
// Serial.println("1-4");
//}
}
}