elecgirl88
New Member
hi guys
I'm doing a final year project which requires me to create an led matrix to be used as a touch pad. Basically it will be used as an access control system and a password will be entered via finger swipes on the surface.
Currently, I'm only able to sense with the whole matrix. I cannot get individual leds to sense on their own. I'm not sure why I cant isolate each led since I'm scanning through each led in the matrix and then checking light levels using the ADC.
I'm using an Arduino pro mini and testing on a 4x4 matrix.
The code is below:
i cant figure out what I'm doing wrong!Please help
thanx in advance
I'm doing a final year project which requires me to create an led matrix to be used as a touch pad. Basically it will be used as an access control system and a password will be entered via finger swipes on the surface.
Currently, I'm only able to sense with the whole matrix. I cannot get individual leds to sense on their own. I'm not sure why I cant isolate each led since I'm scanning through each led in the matrix and then checking light levels using the ADC.
I'm using an Arduino pro mini and testing on a 4x4 matrix.
The code is below:
Code:
// A technique to make analogRead faster
// See http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define num 4
int rows[4]={6,7,8,9}; //PORTS PD6, PD7, PB0, PB1
int cols[5] ={14,15,16,17,14}; //PORTS PC0, PC1, PC2, PC3
//int thresh[4]={0,0,0,0};
//int led[4]={2,3,4,5};
void setup(){
//Serial.begin(9600);
// Adjust prescaler to make analogReadFaster
sbi(ADCSRA,ADPS2) ;
cbi(ADCSRA,ADPS1) ;
cbi(ADCSRA,ADPS0) ;
//turn on each column of leds
for(int i=0; i<num; i++){
pinMode(cols[i],INPUT);
digitalWrite(rows[i],LOW);
pinMode(rows[i],OUTPUT);
}
for(int i=0; i<num; i++){
pinMode(cols[i],OUTPUT);
digitalWrite(cols[i],HIGH);
delay(1000);
digitalWrite(cols[i],LOW);
}
}
void loop(){
unsigned int level=0; //light intensity level variable
for(int i=0; i<num; i++){
digitalWrite(cols[i],LOW); //anodes o/p and low
pinMode(cols[i],OUTPUT);
digitalWrite(rows[i],HIGH); //cathodes o/p and low
pinMode(rows[i],OUTPUT);
}
//delayMicroseconds(10);
for(int i=0; i<num; i++){
digitalWrite(rows[i],LOW);
delayMicroseconds(10);
for(int j=0; j<num; j++){
pinMode(cols[j],INPUT);
delayMicroseconds(200);
while(1){
level = analogRead(cols[j]); //read ADC
// Serial.print(level[i][j]);
//Serial.print(",");
if (level > 50){
pinMode(cols[j+1],OUTPUT);
digitalWrite(cols[j+1],HIGH);
delayMicroseconds(100);
digitalWrite(cols[j+1],LOW);
break;
}
else if (level < 49){
pinMode(cols[j+1],OUTPUT);
digitalWrite(cols[j+1],LOW);
delayMicroseconds(100);
break;
}
}
}
digitalWrite(rows[i],HIGH);
//Serial.println();
}
}
i cant figure out what I'm doing wrong!Please help
thanx in advance
Last edited: