cannot use analog pin >11

skypickle

Active member
this sketch fails

Code:
char potPins[] = {
A10,A11,A12,A13,A16,A17
};  
int potCount = 6;  
int inputPot = 0;   
    
void setup() {
for (int thisPot = 0; thisPot < potCount; thisPot++) 
     pinMode(potPins[thisPot], INPUT);
Serial.begin (9600);
    while (!Serial) { delay(10);}
}

void loop()  {
 for (int thisPot = 0; thisPot < potCount; thisPot++) {
  inputPot = analogRead(potPins[thisPot]);
  Serial.println("potentiometer   ");
  Serial.println(thisPot);
  Serial.println(inputPot);
   delay(1000);
 }
 delay(3000);
}


with the error

Code:
potentiometer3:2:9: error: 'A12' was not declared in this scope
 A10,A11,A12,A13,A16,A17
         ^~~
C:\Users\Stefan\Documents\Arduino\potentiometer3\potentiometer3.ino:2:9: note: suggested alternative: 'A11'
 A10,A11,A12,A13,A16,A17
         ^~~
         A11
potentiometer3:2:13: error: 'A13' was not declared in this scope
 A10,A11,A12,A13,A16,A17
             ^~~
C:\Users\Stefan\Documents\Arduino\potentiometer3\potentiometer3.ino:2:13: note: suggested alternative: 'A11'
 A10,A11,A12,A13,A16,A17
             ^~~
             A11
potentiometer3:2:17: error: 'A16' was not declared in this scope
 A10,A11,A12,A13,A16,A17
                 ^~~
C:\Users\Stefan\Documents\Arduino\potentiometer3\potentiometer3.ino:2:17: note: suggested alternative: 'A11'
 A10,A11,A12,A13,A16,A17
                 ^~~
                 A11
potentiometer3:2:21: error: 'A17' was not declared in this scope
 A10,A11,A12,A13,A16,A17
                     ^~~
C:\Users\Stefan\Documents\Arduino\potentiometer3\potentiometer3.ino:2:21: note: suggested alternative: 'A11'
 A10,A11,A12,A13,A16,A17
                     ^~~
                     A11
exit status 1
'A12' was not declared in this scope


why?

If I change the first three lines to

Code:
char potPins[] = {
A0,A1,A2,A3,A6,A7
};

it compiles no problem
 
What Teensy is selected for Board?

Code as provided builds fine for a T_4.1 that has those pins defined.

When using pins as 'Analog' these lines are not needed - AFAIK:
Code:
void setup() {
[B]//  for (int thisPot = 0; thisPot < potCount; thisPot++)
//    pinMode(potPins[thisPot], INPUT);[/B]
 
I'm using a teensy 4.1

I also noticed two different labels for the same com port to which the teensy is attached.
A regular com13 and a 'teensy port 13'

Bizarre.

I reboot my pc, the duplicate com ports went away and now I can use the higherr analog ports.

Really bizarre
 
btw, when declaring variables and setting pins
what's the difference between

#define potPin1 A10

and

char potPin1 = A10;

Do I need both?
 
@PaulStoffregen thank you. Is there a reference where I could read more about the difference between these two? Memory use? Location in memory (stack vs heap)?
 
you will probably fined info on #define and char in some C programming guide.

#define is similar to a search and replace. any keyword potPin1 will be replaced with A10 at compile time.

I realize analog pins have a char in them but they are not really chars they are ints

int thing[4] = {A0, A1, A2, A3}; // will compile and work

common conventions for pin assignments are

#define SENSOR_PIN A0 // consumes no memory

or

const int sensorPin = A0;// consumes no memory

int sensorPin = A0; // done but consumes 2 bytes of memory
 
Back
Top