I'm attempting to read a piezo sensor that is connected to physical pin 3 of an ATTiny85. According to HLT's pin diagram, this pin is referred to as either Pin 4 or analog input 2. However, when I try to use analogRead to grab values from this pin I get nothing.
I've attached my schematic, and here is a relevant snippet of code that I am using:
void checkPiezo() {
if(piezoCounter < 10) {
// Take a reading
int val = analogRead(piezoPin);
piezoValues[piezoCounter] = val;
} else {
// Find hte average
int avg = 0;
for(int i=0; i<10; i++)
avg += piezoValues[i];
avg = avg/10;
if(avg >= piezoThreshold) {
for(int j=0; j<6; j++) {
for(int i=1; i<=6; i++) {
turnOn(i);
delay(50);
turnOff(i);
delay(50);
}
}
}
// Reset counter
piezoCounter = 0;
}
}
I call this function for every iteration of loop(). It basically just takes 10 consecutive readings of the analog input pin and averages them. If the average exceeds a threshold value (set at 1 right now for testing), all of my charlieplexed LEDs should flash. Instead, nothing happens at all.
Am I referencing the pin correctly? How do I correctly read the value of an analog pin on an ATTiny85?