sandeepmistry/arduino-nRF5

analogRead() should be able to map inputs 0-to-x as A0-to-Ax

Open

#133 建立於 2017年4月3日

在 GitHub 查看
 (7 留言) (0 反應) (0 負責人)C (288 fork)github user discovery
help wanted

倉庫指標

Star
 (952 star)
PR 合併指標
 (PR 指標待抓取)

描述

The default Arduino analogRead() can take 2 different values for each ADC input:

  1. The "analog pin" value, which goes from 0 to NUM_ANALOG_INPUTS, which in most Arduino Uno compatible boards would be 0 to 5:
    analogRead(0);
    analogRead(1);
    ...
    analogRead(5);
    
  2. The pin number, in it's raw "arduino pin" form or Ax global variable:
    analogRead(A0);
    analogRead(A1);
    ...
    analogRead(A5);
    
    Which in boards like the Uno would be the equivalent of:
    analogRead(14);
    analogRead(15);
    ...
    analogRead(19);
    

This is usually done by simply checking the range of the input argument, so in the case of the Uno the analogRead() function would have something along the lines of:

analogRead(uint8_t pin) {
  if (pin < A0) {
    pin += A0;
  }
}

That works well because these boards are configured to have the analog pins mapped immediately after the digital pins and in successive order.

This Arduino core has variants with analog pin mappings that do not follow this convention, and so only "method 2" listed above has been implemented.

This breaks compatibility with any arduino sketches using "method 1", so we should work out a method to map these analog pins in the variant files in a way that allows both methods to work as expected.

貢獻者指南