amosp33
Published

Maximize Inputs

Giving you the ability to add more buttons than analog inputs allow with some restrictions.

IntermediateWork in progress2,495
Maximize Inputs

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Resistor 10k ohm
Resistor 10k ohm
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

2x2x2 Cubed Inputs

the complete 2x2x2 circuit wiring

Code

2x2x2 Cubed Inputs

Arduino
Gives you the ability to get more buttons than inputs
/*
  Created by:

  Amos Parmenter
  July 20th 2019

  The code is setup with the idea that you can
  fit more buttons onto the Arduino that inputs allow.
  The code uses the idea of assigning vector
  identity to a node that will be unique when compared to other nodes.

  This version is setup as 2x2x2 cube and can fit 8 buttons
  into 6 analog slots. It is scalable in cubed
  form (3x3x3.(mega), 4x4x4.(mega) , 5x5x5.(mega maxed inputs)).
  The 5x5x5 uses 15 analog pins but in return gives you 125 buttons.

  There are mathematical complications to this code that
  I haven’t fully worked out.To be sure you don’t get false
  positives for buttons you can only turn on one button at a time.
  In most cases you can have two buttons on at once but not
  every two combinations are allowed.
  Any three combinations will always give you false positives.
  The simulations I wired in 123D Circuits with the 2x2x2
  cubed wiring and is running this version of code.

*/


const int x0 = 0; // input pins
const int x1 = 1; // input pins
const int y0 = 2; // input pins
const int y1 = 3; // input pins
const int z0 = 4; // input pins
const int z1 = 5; // input pins

int x_0; // nodes
int x_1; // nodes
int y_0; // nodes
int y_1; // nodes
int z_0; // nodes
int z_1; // nodes

bool btn0 = false;
bool btn1 = false;
bool btn2 = false;
bool btn3 = false;
bool btn4 = false;
bool btn5 = false;
bool btn6 = false;
bool btn7 = false;

bool vectorX = false;
bool vectorY = false;
bool vectorZ = false;

bool btnBoolMatrix[] = {btn0, btn1, btn2, btn3,
                        btn4, btn5, btn6, btn7
                       };

int analogList[8][3] = {
  {x0, y0, z0},
  {x1, y0, z0},
  {x0, y1, z0},
  {x1, y1, z0},
  //============
  {x0, y0, z1},
  {x1, y0, z1},
  {x0, y1, z1},
  {x1, y1, z1}
};

int btnMatrix[8][3] = {
  {x_0, y_0, z_0},
  {x_1, y_0, z_0},
  {x_0, y_1, z_0},
  {x_1, y_1, z_0},
  //============
  {x_0, y_0, z_1},
  {x_1, y_0, z_1},
  {x_0, y_1, z_1},
  {x_1, y_1, z_1}
};

bool vectorXYZ [3] {vectorX, vectorY, vectorZ};


void setup()
{
  Serial.begin(9600);

  pinMode(x0, INPUT);
  pinMode(x1, INPUT);
  pinMode(y0, INPUT);
  pinMode(y1, INPUT);
  pinMode(z0, INPUT);
  pinMode(z1, INPUT);

}

void loop() {

  /* This section allows you to check
     the active button by entering the number
     1 into the Serail monitor
  */

  while (Serial.available() < 0);
  int options = Serial.read() - '0';
  if (options == 1) {

    checkBtnList();
  }

}





void checkBtnList() {

  for (int i = 0; i < 8; i++) {

    for (int i = 0; i < 3; i++) {
      vectorXYZ[i] = false;
    }

    for (int j = 0; j < 3; j++) {

      btnMatrix[i][j] = analogRead(analogList[i][j]);



      if (btnMatrix[i][j] > 250 ) {
        vectorXYZ[j] = true;
      } else {
        vectorXYZ[j] = false;
      }

      if (j == 2) {
        if (vectorXYZ[0] == true && vectorXYZ[1] == true && vectorXYZ[2] == true) {
          btnBoolMatrix[i] = true;
        } else {
          btnBoolMatrix[i] = false;
        }
      }

    }
  }

  for (int s = 0; s < 7; s++) {
    Serial.print(btnBoolMatrix[s]);
    Serial.print(" ");
  }
  Serial.println(btnBoolMatrix[7]);
  
}

Credits

amosp33
1 project • 2 followers
Contact

Comments

Please log in or sign up to comment.