Author Topic: analogRead P3  (Read 1642 times)

sv

  • Newbie
  • *
  • Posts: 1
analogRead P3
« 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);
}
« Last Edit: March 30, 2017, 01:32:24 pm by sv »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: analogRead P3
« Reply #1 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.