Digistump Forums

The Digispark => Digispark (Original) Support => Topic started by: sv on March 30, 2017, 01:28:32 pm

Title: analogRead P3
Post by: sv on March 30, 2017, 01:28:32 pm
Hi, guys!
How to analogRead from P3 properly?
I want to control LED intensity with Sharp IR distance sensor (2Y0A21). P2 and P4 works fine with sensor, but with P3 I have wrong results.
Seems, analogRead returns max value always and LED is always on.
Code: [Select]
int intensityPin = 3;

void setup() {
}

void loop() {
  delay(300);
 
  int intensity = analogRead(intensityPin);
  intensity = map(intensity, 0, 1023, 0, 255);
  analogWrite(1, intensity);
}
Title: Re: analogRead P3
Post by: exeng on March 30, 2017, 02:13:22 pm
Pin 3 on the  Digispark has 1k pullup resistor on it. If you want to  use  it for analog reads you are  going to have to  come up with some  external circuitry to  compensate for that. Unless you have to absolutely use that pin, it's not recommended as this pin is also used for USB communication  when doing uploads. See the Digispark pin out notes in the wiki section.