Boo0ns / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Macros to provide basic pin information about a particular board. #495

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From Paul Stoffregen:

"#1: The total number of digital pins, usable with pinMode, digitalRead, 
digitalWrite.

#2: The total number of analog pins, usable with analogRead.

#3: A macro that takes an analog pin as input and outputs the corresponding 
digital pin, or -1 if that analog pin does not have any corresponding digital 
pin, or -1 if the input is greater than the maximum analog pin number.

#4: A macro that takes a digital pin as input and returns true if that pin has 
PWM capability, or false if it does not, or false if the input is greater than 
the maximum digital pin number."

This is in some ways a subset of issue #59.  I think most or all of these 
particular ones make sense given the more CPU-neutral build system and core 
we'll have in 1.0.

Look at the Firmata and ArduinoTestSuite libraries for examples of places that 
might need this functionality.

Original issue reported on code.google.com by dmel...@gmail.com on 5 Mar 2011 at 4:27

GoogleCodeExporter commented 9 years ago
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define digitalPinCount           70
#define analogPinCount            16
#define analogPinToDigitalPin(p)  ((p < 16) ? (p) + 54 : -1)
#define digitalPinHasPWM(p)       (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p) 
< 46))
#else
#define digitalPinCount           20
#define analogPinCount             6  // fio, mini, nano have 8...
#define analogPinToDigitalPin(p)  ((p < 6) ? (p) + 14 : -1)
#if defined(__AVR_ATmega8__)
#define digitalPinHasPWM(p)       ((p) == 9 || (p) == 10 || (p) == 11)
#else
#define digitalPinHasPWM(p)       ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 
|| (p) == 10 || (p) == 11)
#endif

Original comment by dmel...@gmail.com on 7 Mar 2011 at 4:16

GoogleCodeExporter commented 9 years ago
Should be: #define digitalPinHasPWM(p)       (((p)>= 2&&  (p)<= 13) || ((p)>= 
44&&  (p)<= 46))

Original comment by dmel...@gmail.com on 8 Mar 2011 at 3:13

GoogleCodeExporter commented 9 years ago
https://github.com/arduino/Arduino/commit/d338f22bde9b83796af4d627d085dfb25a0a40
5f

Original comment by dmel...@gmail.com on 12 Aug 2011 at 10:28