Module 3.3.3 why is pinBatt an int?

Thank you for the course which I am really enjoying and learning a lot. This is a trivial question but has me puzzled. Why does the code say

int pinBatt = A6:

as I had assumed int represented integer. Is A6 shorthand for a number?




Hi Roy,

A6 is a constant (which is a variable with a value that cannot be changed) whose value is an integer.  There are a bunch of predefined constants and variables that are part of the Arduino programming environment.

The exact value of the A6 constant isn't generally of interest, because all we usually care to know is that it refers to a particular pin labelled A6 on the board.

The statement:

int pinBatt = A6;

means you are declaring (the intent to later use) a variable called pinBatt which is an integer, and whose value initially is the value of A6 (which is 20 or 60 or something like that), until you change it if at all.

-harold

Hi Roy. 

Yes, as @htarold mentioned, A6 is actually the name of a constant defined in a different file where the Wildlogger board is defined. If you go digging into the board definition files, you'll find that the ones pertaining to Wildlogger have these lines:

static const uint8_t A0 = 24;
static const uint8_t A1 = 25;
static const uint8_t A2 = 26;
static const uint8_t A3 = 27;
static const uint8_t A4 = 28;
static const uint8_t A5 = 29;
static const uint8_t A6 = 30;
static const uint8_t A7 = 31;

This means you can use A0 as a replacement for the number 24. The number 24 happens to map to the specific "analog input 0" pin, hence the name A0. 

Also "static const" just means that the number won't change or is a constant. "uint8_t" is a standard way to specify the size of a variable. It's shorthand for unsigned 8-bit integer data type. 

When we declare something as an 'int', we're actually saying it's an int16_t or "signed 16-bit integer data type". We were thinking to get more into dealing with memory handling and data types in a future course that would go more in-depth for a specific application. In this course, we're mainly just hoping to introduce people to programming for Arduinos as a stepping stone for the more complex nuances and projects later.

Hope that helps. 

Akiba

 

Hi Akiba, Jacinta,

Jjust to say I've complted all the videos through to end of 3.3.1b successfully - no problems!  It snowed here in the North of England last night, so was measuring temperature today!

Many thanks

Rob