Data Types in C are used to declare variables or functions of different types. The type of a variable determines how much storage space is occupied.
This is a list of the Data types used in Arduino Programming:
- Void – is used only in function declarations. It only indicates that the function is expected to return no information to the function from which it was called.
- Boolean – It holds only 2 values (True and False). Each Boolean is one Byte of Memory.
- Char – it stores a character value. The character’s are written in single quotes ‘X’ like this.
- Unsigned Char – it occupies one byte of memory. The unsigned char data type encodes numbers from 0 to 255.
- byte – stores an 8-bit unsigned number, from 0 to 255
- int – Integers are the primary data-type for number storage. int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) – 1). The int size varies from board to board. On the Arduino Due, for example, an int stores a 32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31) – 1).
- unsigned int – are the same as int in the way that they store a 2 byte value. Instead of storing negative numbers, however, they only store positive values, yielding a useful range of 0 to 65,535 (2^16) – 1). The Due stores a 4 byte (32-bit) value, ranging from 0 to 4,294,967,295 (2^32 – 1).
- word – On the Uno and other ATMEGA based boards, a word stores a 16-bit unsigned number. On the Due and Zero, it stores a 32-bit unsigned number.
- long – are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647.
- unsigned long – are extended size variables for number storage and store 32 bits (4 bytes). Unlike standard longs, unsigned longs will not store negative numbers, making their range from 0 to 4,294,967,295 (2^32 – 1).
- short – A short is a 16-bit data-type. On all Arduinos (ATMega and ARM based), a short stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) – 1).
- float – is a number that has a decimal point. Floating-point numbers are often used to approximate the analog and continuous values because they have greater resolution than integers.
- double – Double precision floating-point number occupies four bytes. That is, the double implementation is exactly the same as the float, with no gain in precision. On the Arduino Due, doubles have 8-byte (64 bit) precision.
Variables in C programming language, which Arduino uses, have a property called scope. A scope is a region of the program and there are three places where variables can be declared
Variables in C programming language, which Arduino uses, have a property called scope. A scope is a region of the program and there are three places where variables can be declared.
Local Variable – Variables that are declared inside a function or block are local variables. They can be used only by the statements that are inside that function or block of code. Local variables are not known to function outside their own
Global Variable – Global variables are defined outside of all the functions, usually at the top of the program. The global variables will hold their value throughout the life-time of your program. A global variable can be accessed by any function.
One Reply on “Arduino Programming – Simplified”