Attiny85 newb- simultaneous analogRead / Write

hello,

i am attempting to use an attiny85 to read incoming voltage, and based on that voltage reading, write out a pwm value. having some big problems. i’m using the arduino ide with the Arduino-Tiny core. i can program the attiny with (seemingly) no problem. now using this circuit-

http://s13.postimg.org/3sb7lbu3b/grady_ … _v3_bb.jpg

here is the code:

// to run on attiny85

const byte pwmPin = 0;
const byte analogInPin = A2;

void setup() {
  pinMode(pwmPin, OUTPUT);
}

void loop() {
  int analogIn = analogRead(analogInPin);
  analogWrite(pwmPin, analogIn);
}

should be simple- i should get a reading from the arduino micro analogin of around 790- which should equate to 3.86 volts. but instead i get 1023- the value of the full 5v.

any thoughts? thanks in advance!

My guess is that this is confusing the compiler.

const byte analogInPin = A2;

Is “A2” a byte ? Try this instead.

const byte analogInPin = 2;

I’ll assume you’ve measured the 3.86v, as configured, on the Tiny’s pin3.

i needed to re-range the 10bit adc input to 8bit pwm out. using the arduino map() function.

analogIn = map(analogIn, 0, 1023, 0, 255);

it works great! thank you.