I've got a strange problem with an ATTiny85. Have a circuit setup that is using 2 resistive touch sensors to feed 2 inputs that turn on 2 LEDs. In short, touch sensor 1 > LED 1 goes on, touch sensor 2 > LED 2 goes on. I have confirmed that this works on an Arduino Uno. My setup has the 2 touch circuits feeding the ATTiny on Pin 3 and Pin 4 (the 2 analog inputs - see pic below). Everything works fine for Pin 3, but on Pin 4 the LED blinks on and off. I also swapped the touch sensor circuits to make sure the problem was with the ATTiny and not the electronics, and confirmed that it is the input on Pin 4 that seems to be failing.
I decided to strip things down and focus on Pin 4. I also stripped the code down to focus on Pin 4. The touch sensor works by supplying ~4.5V to Pin4 when running and not touched (so its HIGH). It is a resistive touch sensor, so when I complete the loop (by touching 2 pins with my finger), the circuit triggers a voltage drop. Using AnalogRead, this translates to the code seeing 1023 normally, and the value drops somewhere below 400 when touching the sensor. Again, this works for Pin3 and the code around Pin3. The code for Pin4 is identical (see below). When I run the code, it uses tchValB = analogRead(tchPadB); to get the voltage value, and the LED will go on and off constantly. I was able to confirm that the value is somewhere around 4 even without my touching the sensor. I did this by simply playing with *if (tchValB < tchValSens) * and setting tchValSens to lower and lower values until the LED stopped blinking. A value of 5 blinks, and 4 does not. Again, if I put the circuit input pin on Pin 3 it works fine and stays at 1023 until I touch it (so I know the circuit is fine), and it works on the Uno as well - both touch circuits read 1023 until touched. It seems that Pin4 is not reading/translating AnalogRead correctly. I used the HLT wiki example to get the Arduino IDE working with the ATTiny85. Has anyone heard of there being a problem with AnalogRead for this? I found something vague about another code porting example to make the Arduino IDE work with another ATTiny, and it mentioned an analogRead issue, but nothing specific to this one. Oh, I also tried another ATTiny chip as well to make sure that mine was not fried. Same result.
I'm stumped.

//***********************
//CONFIGURABLE VALUES
int tchValSens = 990; //val 1023 is open circuit. 0 is closed. Dry fingers use 900, humid, damp, use 100
//************************
#define statusLED 2 //Digital In D1 - used to show timer countdown.
#define ledCtrlrB 1 //Digital In D6 MUST BE A PWM PIN (oddly my PWM pin#11 does not work) - controls IRF530 transistor > LED lights
int tchPadB = 4; //Analog In A2 Pin4
int i = 0;
int dlyTime = 20; //delay timer (for overall loop) in MS.
int statCounter = 0; //counter for the status LED.
int tchValB = 0; //Holder for tchValB
int ledStateB = LOW; //Holds the current state of the LED lights (HIGH=on LOW=off)
int startBrightness = 255; //Initial brightness of the LED 0-255
int statusLEDFlashDur = 100; //In Milliseconds - Flash period for MSTimer2 to flash the LED in ms. 100ms
void setup ()
{
pinMode(tchPadB, INPUT); //Setup the tchPadB as an Input
pinMode(statusLED, OUTPUT); //Setup the statusLED as an Output
pinMode(ledCtrlrB, OUTPUT); //Setup the ledCtrlrB as an Output
}
void flash() {
digitalWrite(statusLED, HIGH);
delay(60);
digitalWrite(statusLED, LOW);
}
void rampLEDDownNoff(byte ledPin, byte lval, int dly, byte ledStateWhich)
{
if (dly == 0)
{
analogWrite(ledPin,0);
}
else
{
while(lval > 0)
{
analogWrite(ledPin,lval);
lval--;
delay(dly);
}
//make it is all the way off
digitalWrite(ledPin, LOW);
}
ledStateB = LOW;
}
void rampLEDupOn(byte ledPin, byte lval, byte ledNormVal, int dly, byte ledStateWhich)
{
if (dly == 0)
{
analogWrite(ledPin,255);
}
else
{
while(lval < ledNormVal)
{
analogWrite(ledPin,lval);
lval++;
delay(dly);
}
}
ledStateB = HIGH;
}
void loop (){
tchValB = analogRead(tchPadB);
if (tchValB < tchValSens)
{
//check state and turn led on or off - if the LED is off turn it on and vice-versa:
if (ledStateB == LOW)
{
rampLEDupOn(ledCtrlrB, 0, 255, 0, 2); //5
}
else
{
rampLEDDownNoff(ledCtrlrB, 255, 0, 2); //10
}
delay(500);
}
}