I'm having a play with the ATtiny45 and can program and make it do what i want to do but I have a problem where I can't read ADC1, A1
Using the following code I can change the flash speed of the LED to prove I can read the inputs.
I can read ADC3 & 2 But not 1
I tried defining it as PB2 & A1(wont compile)
Am I being missing something, I've tried several Atiny45 in case it's duff chip
}
void loop()
{
ADCIN = analogRead(VoltsIn) ;
digitalWrite(greenPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(ADCIN); // wait for ADC Value
digitalWrite(greenPin, LOW); // turn the LED off by making the voltage LOW
delay(ADCIN); // wait for ADC Value
}
Thanks if anyone can point me in the right direction
After some more investigation I have found the problem but don't know the answer.
It appears that PB1 & 1 (aka ADC1,PB2) are the same pin when I program.
With the code below the LED is very very faint but does flash in line with the ADC1 voltage.
More confusing as soon as a define the ADC pin as one of the other 3 ADCs the LED flashes at full brightness.
even more confusing is I can flash the LED by addressing it as either PB1 or just 1.
(If I try to define pins as D1 or A1 I get a compile error)
Thanks for the response.
Before I saw your reply I removed the line making Voltsin an input and this fixed the issue but I thought it was good practice to declare inputs and outputs?
I had already looked at the thread you highlighted and its helped a little but I'm still unclear why I can't define ADC1 (1) as an input but I can the other 3 ADCs (0,2,3)
is this a bug in the ATtiny library or do i never need to define inputs?
I thought it was good practice to declare inputs and outputs?
It is. For pins that can be either. For analog pins that can only be INPUT, it isn't necessary (and can actually cause problems because pinMode knows nothing about the existence of analog pins).
Again thanks for the response.
I was going off of this sheet which showed the ATtiny45 A1 could also be D2 (input or output) so I assumed I had to define it, or am I missing the point which is quite probable
So it's my understanding they are defined when you analogRead(1,2,3,4) as per the analogue pinouts below
Like most people here I'm learning as I go, but things I've done with the Uno board don't seem to work with the ATtiny, i just assume the library is not as mature.