Inputs and outputs

Hi, I have a code for my experiment which has 4x4 which can read the outputs individually. I also can make a single sensor by using that code. How do I get two outputs and inputs? I can only get results in one column.

Thanks.

Code:

// 4x4 code 

#include <math.h>
#include <stdio.h>


const int X0 = A0; 
const int X1 = A1;        // Analog    (0-1023)
const int X2 = A2;
const int X3 = A3;

const int Y0 = 0;
const int Y1 = 1;         // Digital     (Floating/ 5v)
const int Y2 = 2;
const int Y3 = 3;
long time =  0;

int SensorValue = 0;      // Buffer
//int treshold    =40;      // Treshold
 
void setup() {

 
   Serial.begin(115200);  // Sampling rate
   


 }

void loop() {

//-----------------------------Y0 HIGH--------------------------------------------------------
 


 pinMode(Y0, OUTPUT);
pinMode(Y1, INPUT);                  
pinMode(Y2, INPUT);               // INPUT is Defining Y ports to be low impedance
pinMode(Y3, INPUT);

               
 digitalWrite(Y0, HIGH);  

 {
 SensorValue= analogRead(X0);            //     X0Y0
 
  
   Serial.print(SensorValue);  
Serial.print("      ");  

 SensorValue= analogRead(X1);            //     X1Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 

 
 SensorValue= analogRead(X2);          //     X2Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 
 
 SensorValue= analogRead(X3);          //     X2Y0
Serial.print("      "); 
   Serial.print(SensorValue);  
   Serial.print( " ; " );

  }
// --------------------------------------------------------Y1----------------------------
pinMode(Y0, INPUT);
pinMode(Y1, OUTPUT);                  
pinMode(Y2, INPUT);               // INPUT is Defining Y ports to be low impedance
pinMode(Y3, INPUT);

               
 digitalWrite(Y1, HIGH);  

 {
 SensorValue= analogRead(X0);            //     X0Y0
 
  
   Serial.print(SensorValue);  
Serial.print("      ");  

 SensorValue= analogRead(X1);            //     X1Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 

 
 SensorValue= analogRead(X2);          //     X2Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 
 
 SensorValue= analogRead(X3);          //     X2Y0
Serial.print("      "); 
   Serial.print(SensorValue);  
   Serial.print( " ; " );


  
 }
//--------------------------------------Y2----------------------

pinMode(Y0, INPUT);
pinMode(Y1, INPUT);                  
pinMode(Y2, OUTPUT);               // INPUT is Defining Y ports to be low impedance
pinMode(Y3, INPUT);

               
 digitalWrite(Y2, HIGH);  

 {
 SensorValue= analogRead(X0);            //     X0Y0
 
  
   Serial.print(SensorValue);  
Serial.print("      ");  

 SensorValue= analogRead(X1);            //     X1Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 

 
 SensorValue= analogRead(X2);          //     X2Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 
 
 SensorValue= analogRead(X3);          //     X2Y0
Serial.print("      "); 
   Serial.print(SensorValue);  
   Serial.print( " ; " );

 
 }
//-------------------------------Y3---------------------------
pinMode(Y0, INPUT);
pinMode(Y1, INPUT);                  
pinMode(Y2, INPUT);               // INPUT is Defining Y ports to be low impedance
pinMode(Y3, OUTPUT);

               
 digitalWrite(Y3, HIGH);  

 {
 SensorValue= analogRead(X0);            //     X0Y0
 
  
   Serial.print(SensorValue);  
Serial.print("      ");  

 SensorValue= analogRead(X1);            //     X1Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 

 
 SensorValue= analogRead(X2);          //     X2Y0
 
   Serial.print(SensorValue);  
  Serial.print("      "); 
 
 SensorValue= analogRead(X3);          //     X2Y0
Serial.print("      "); 
   Serial.print(SensorValue);  
   Serial.print( " ; " );

 time= micros();
Serial.print(time); 
   delay(500);
   Serial.println("");
  
 }
 }

}

For my 2x2
// 2x2 code

#include <math.h>
#include <stdio.h>


const int X0 = A0; 
const int Y0 = 0;
const int X1 = A1;
const int Y1 = 1;

int SensorValue = 0;      // Buffer
//int treshold    =40;      // Treshold
 
void setup() {

 
   Serial.begin(115200);  // Sampling rate
   


 }

void loop() {

//-----------------------------Y0 HIGH--------------------------------------------------------
 


 pinMode(Y0, OUTPUT);

              
 digitalWrite(Y0, HIGH);  //3.3v

 {
 SensorValue= analogRead(X0);            //     X0Y0


   Serial.print(SensorValue);  
  Serial.println("      "); 
   
   
   delay(100);
  
 }



//---------Y1 High-
 pinMode(Y0, INPUT);
pinMode(Y1, OUTPUT);  

  digitalWrite(Y1, HIGH);  

{
 SensorValue= analogRead(X0);            //     X0Y0
 
  
   Serial.print(SensorValue);  
Serial.println("      ");  

 SensorValue= analogRead(X1);            //     X1Y0
 
   

   delay(500);
   Serial.print(";");
}}

Give us a link to your keypad.

 pinMode(Y2, INPUT);               // INPUT is Defining Y ports to be low impedance

Say, what?

Hi,
please go back to you first post and add code tags please.

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom..... :slight_smile:

When I put the semicolon then went to the serial monitor 1 got 1 column with results for example. eg. 43 ;67. Does that mean I was getting two different outputs ? As I set it up with two materials and two resistors to the Teensy 3.1.