Skip to content

Arduino 1.5.6-r2 Bug in AnalogRead() #2016

Closed
@DenDanny

Description

@DenDanny

On an Arduino DUE::

The example sketch below does not work on 1.5.6-r2.

I have an LED connected between a digital and an analogue pin. But in 1.5.6-r2, once I use the AnalogRead() - the LED will no longer be 'controllable' using the pinMode/DigitalWrite. The sketch demonstrates this because (in 1.5.6-r2) the LED will stop blinking after the AnalogRead(); whilst in 1.5.4 this sketch runs flawlessly, and the LED blinks happily away -as expected...

All the best,
Danny.

// for Arduino DUE:
const int anode = 24;         // Digital pin 22
const int cathode = 54;       // Analog pin 0
const int p = 250;

void setup() {
  analogReadResolution(12);
  pinMode(anode, OUTPUT);
  pinMode(cathode, OUTPUT);
  Serial.begin(115200);   
}

void loop() {
  
  // Led OFF
  digitalWrite(anode, LOW);
  digitalWrite(cathode, LOW);
  delay(p);
  
  // Reverse Charge
  digitalWrite(anode, LOW);
  digitalWrite(cathode, HIGH);
  
  // Measure
  pinMode(cathode, INPUT);
  delay(20);
  int val = analogRead(0);    //--> THIS is the culprit (!)
  
  // report
  Serial.print("analogRead: ");
  Serial.println(val,DEC);
  
  // Led ON
  //## --> DOES'T WORK ON 1.5.6-r2(!) The LED remains 'off' and never blinks ON again!
  //## --> Works fine on 1.5.4, blinks -as expected.
  pinMode(cathode, OUTPUT);
  digitalWrite(anode, HIGH);
  digitalWrite(cathode, LOW);
  delay(p);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: DuplicateAnother item already exists for this topic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions