Data Types

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

char var = val;

A data type used to store a character value. Character literals are written in single quotes, like this: 'A' (for multiple characters - strings - use double quotes: "ABC").

bool var = val;

A bool holds one of two values, true or false. (Each bool variable occupies one byte of memory.)

byte var = val;

A byte stores an 8-bit unsigned number, from 0 to 255.

short var = val;

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).

word var = val;

A word can store an unsigned number of at least 16 bits (from 0 to 65535).

array

All of the methods below are valid ways to create (declare) an array. int myInts[6]; int myPins[] = {2, 4, 8, 3, 6}; int mySensVals[6] = {2, 4, -8, 3, 2}; char message[6] = "hello";

unsigned char var = val;

An unsigned data type that occupies 1 byte of memory. Same as the byte datatype. The unsigned char datatype encodes numbers from 0 to 255. For consistency of Arduino programming style, the byte data type is to be preferred.

String(val)

Constructs an instance of the String class. There are multiple versions that construct Strings from different data types (i.e. format them as sequences of characters), including:

float var = val;

Datatype for floating-point numbers, a number that has a decimal point. Floating-point numbers are often used to approximate analog and continuous values because they have greater resolution than integers. Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information.

double var = val;

Double precision floating point number. On the Uno and other ATMEGA based boards, this occupies 4 bytes. That is, the double implementation is exactly the same as the float, with no gain in precision.

int var = val;

Integers are your primary data-type for number storage. On the Arduino Uno (and other ATmega based boards) an 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). On the Arduino Due and SAMD based boards (like MKR1000 and Zero), 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 var = val;

On the Uno and other ATMEGA based boards, unsigned ints (unsigned integers) are the same as ints in 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). The difference between unsigned ints and (signed) ints, lies in the way the highest bit, sometimes referred to as the "sign" bit, is interpreted. In the Arduino int type (which is signed), if the high bit is a "1", the number is interpreted as a negative number, and the other 15 bits are interpreted with (2's complement math).

unsigned long var = val;

Unsigned long variables are extended size variables for number storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won't store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1).

long var = val;

are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647.

boolean

boolean is a non-standard type alias for bool defined by Arduino. It's recommended to instead use the standard type bool, which is identical.

string

represented in two ways. you can use the String data type, which is part of the core as of version 0019, or you can make a string out of an array of type char and null-terminate it. This page described the latter method. For more details on the String object, which gives you more functionality at the cost of more memory, see the String object page.

size_t var = val;

size_t is a data type capable of representing the size of any object in bytes. Examples of the use of size_t are the return type of sizeof() and Serial.print().

void

used only in function declarations. It indicates that the function is expected to return no information to the function from which it was called.


Ensembles d'études connexes

AP human geography semester exam study guide

View Set

Chapter 37 (Transport Operations)

View Set

Endocrine Disorders Practice Questions

View Set

ECON 182 Microeconomics - Chapter 10 & 11 -Chapter Readings

View Set

Fluid & Electrolyte Balance Application Exam

View Set

Intro to Business 1100- Module 2

View Set