I am working on making a keypad with 6 capacitance sensors. I am using an arduino diecimilia. I tried using the sample code found here: arduino.cc/playground/Code/CapacitiveSensor
The problem is no matter what is touching it, input digital 13 always returns a value of 16 in the serial output.
Does anyone have any ideas why this might be the case?
Thank you so much!!!!
Note: I'm also named Mario, but I'm not the person who wrote the sample code below.
Mario Becker, Fraunhofer IGD, 2007
// sensor key
#define KEYPORT PORTB
#define KEYDDR DDRB
#define KEYPIN PINB
#define KEY0 PB0 // capture input - digital 8
#define KEY1 PB1 // capture input - digital 9
#define KEY2 PB2 // capture input - digital 10
#define KEY3 PB3 // capture input - digital 11
#define KEY4 PB4 // capture input - digital 12
#define KEY5 PB5 // capture input - digital 13
void setup()
{
Serial.begin(9600); // connect to the serial port
}
// returns capacity on one input pin
// pin must be the bitmask for the pin e.g. (1<<PB0)
char getcap(char pin)
{
char i = 0;
KEYDDR &= ~pin; // input
KEYPORT |= pin; // pullup on
for(i = 0; i < 16; i++)
if( (KEYPIN & pin) ) break;
KEYPORT &= ~pin; // low level
KEYDDR |= pin; // discharge
return i;
}
void loop ()
{
char capval[6];
char pinval[6] = {1<<KEY0,1<<KEY1,1<<KEY2,1<<KEY3,1<<KEY4,1<<KEY5};
delay(1000);
for(char i = 0; i < 6; i++)
{
capval = getcap(pinval*);*
* Serial.print("digital ");*
* Serial.print(i+8, DEC);*
* Serial.print(": ");*
_ Serial.println(capval*, DEC);
}
Serial.println("");
}*_