Reference.VariableDeclaration History

Hide minor edits - Show changes to markup

December 07, 2012, at 04:23 PM by Roberto Guido - removed broken link to missing page "keywords"
Changed lines 77-79 from:

You can name a variable any word that is not already one of the keywords? in Arduino. Avoid beginning variable names with numeral characters.

to:

You can name a variable any word that is not already one of the keywords in Arduino. Avoid beginning variable names with numeral characters.

June 25, 2009, at 12:57 PM by Paul Badger -
Changed lines 14-16 from:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. See below for an example.

to:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. See below for an example.

Changed lines 29-40 from:

Using Variables

Once variables have been declared, they are used by setting the variable equal to the value one wishes to store with the assignment operator (single equal sign). The assignment operator tells the program to put whatever is on the right side of the equal sign into the variable on the left side.

inputVariable1 = 7;             // sets the variable named inputVariable1 to 7
inputVariable2 = analogRead(2); // sets the variable named inputVariable2 to the 
                                // (digitized) input voltage read from analog pin #2

Variable Rollover

to:

Variable Rollover

Added lines 42-53:

Using Variables

Once variables have been declared, they are used by setting the variable equal to the value one wishes to store with the assignment operator (single equal sign). The assignment operator tells the program to put whatever is on the right side of the equal sign into the variable on the left side.

inputVariable1 = 7;             // sets the variable named inputVariable1 to 7
inputVariable2 = analogRead(2); // sets the variable named inputVariable2 to the 
                                // (digitized) input voltage read from analog pin #2

June 25, 2009, at 12:55 PM by Paul Badger -
Changed lines 39-40 from:

Variable Rollover

to:
June 25, 2009, at 12:53 PM by Paul Badger -
Changed lines 14-16 from:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over? when the value stored exceeds the space assigned to store it. See below for an example.

to:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. See below for an example.

June 25, 2009, at 12:48 PM by Paul Badger -
Changed line 26 from:

[@ int calibrationVal = 17; // declare and set initial value

to:

[@ int calibrationVal = 17; // declare calibrationVal and set initial value

June 25, 2009, at 12:31 PM by Paul Badger -
Changed lines 14-16 from:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. See below for an example.

to:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over? when the value stored exceeds the space assigned to store it. See below for an example.

June 25, 2009, at 12:30 PM by Paul Badger -
June 25, 2009, at 12:28 PM by Paul Badger -
Deleted lines 8-15:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. For example a byte

Another important choice that programmers face is where to declare variables.

 the specific place that variables are declared influences how the program will see the variable. This is called variable scope.

Variables may be initialized (assigned a starting value) when they are declared or not. It is always good programming practice however to make sure that a variable has valid data in it, before it is accessed for some other purpose.

Changed lines 14-30 from:
to:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. See below for an example.

Variable Scope

Another important choice that programmers face is where to declare variables. The specific place that variables are declared influences how various functions in a program will see the variable. This is called variable scope.

Initializing Variables

Variables may be initialized (assigned a starting value) when they are declared or not. It is always good programming practice however to double check that a variable has valid data in it, before it is accessed for some other purpose.

Example:

 int calibrationVal = 17;  // declare and set initial value

Added lines 39-51:

Variable Rollover

When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacity, note that this happens in both directions.

   int x
   x = -32,768;
   x = x - 1;       // x now contains 32,767 - rolls over in neg. direction

   x = 32,767;
   x = x + 1;       // x now contains -32,768 - rolls over

June 25, 2009, at 12:17 PM by Paul Badger -
Changed lines 9-10 from:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Also the specific place that variables are declared influences how the program will see the variable. This is called variable scope.

to:

Programmers should consider the size of the numbers they wish to store in choosing variable types. Variables will roll over when the value stored exceeds the space assigned to store it. For example a byte

Another important choice that programmers face is where to declare variables.

 the specific place that variables are declared influences how the program will see the variable. This is called variable scope.
June 25, 2009, at 12:11 PM by Paul Badger -
Added lines 63-66:

Variable Scope

  • Variable Scope
September 08, 2008, at 04:19 AM by Paul Badger -
Changed lines 32-35 from:
   char errorMessage = {"choose another option"}; // see string 

to:
   char errorMessage = {"choose another option"}; // see string @]

September 08, 2008, at 04:18 AM by Paul Badger -
Changed lines 31-35 from:
   long speedOfLight = 186000;
   char 

to:
   unsigned long speedOfLight = 186000UL;
   char errorMessage = {"choose another option"}; // see string 

September 08, 2008, at 04:16 AM by Paul Badger -
Changed lines 27-28 from:

Example

to:

Examples

[@ int lightSensVal;

   char currentLetter;
   long speedOfLight = 186000;
   char 

September 08, 2008, at 04:13 AM by Paul Badger -
Changed lines 39-40 from:

This example shows all three useful operations with variables. It tests the variable ( if (inputVariable2 < 100) ), it sets the variable if it passes the test ( inputVariable2 = 100 ), and it uses the value of the variable as an input to the delay() function ( delay(inputVariable2) )

to:

This example shows all three useful operations with variables. It tests the variable ( if (inputVariable2 < 100) ), it sets the variable if it passes the test ( inputVariable2 = 100 ), and it uses the value of the variable as an input parameter to the delay() function ( delay(inputVariable2) )

September 08, 2008, at 04:13 AM by Paul Badger -
Changed lines 3-4 from:

A variable is a way of naming and storing a value for later use by the program, such as data from a analog pin set to input. (See pinMode for more on setting pins to input or output.)

to:

A variable is a way of naming and storing a value for later use by the program, such as data from a sensor or an intermediate value used in a calculation.

Added lines 11-12:

Variables may be initialized (assigned a starting value) when they are declared or not. It is always good programming practice however to make sure that a variable has valid data in it, before it is accessed for some other purpose.

September 06, 2008, at 09:02 PM by Paul Badger -
Changed lines 27-28 from:

Once a variable has been set (assigned a value), you can test its value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable2 is less than 100, then sets a delay based on inputVariable2 which is a minimum of 100:

to:

Once a variable has been set (assigned a value), you can test its value to see if it meets certain conditions, or you can use its value directly. For instance, the following code tests whether the inputVariable2 is less than 100, then sets a delay based on inputVariable2 which is a minimum of 100:

September 06, 2008, at 09:01 PM by Paul Badger -
Changed lines 44-48 from:

declares that inputVariable is an int, and that its initial value is zero.

Possible types for variables are:

to:

Some variable types

September 06, 2008, at 09:00 PM by Paul Badger -
Changed lines 27-28 from:

Once a variable has been set (or re-set), you can test its value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable2 is less than 100, then sets a delay based on inputVariable2 which is a minimum of 100:

to:

Once a variable has been set (assigned a value), you can test its value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable2 is less than 100, then sets a delay based on inputVariable2 which is a minimum of 100:

Changed line 30 from:

if (inputVariable < 100)

to:

if (inputVariable2 < 100)

Changed line 32 from:
  inputVariable = 100;
to:
  inputVariable2 = 100;
Changed lines 35-38 from:

delay(inputVariable);@]

This example shows all three useful operations with variables. It tests the variable ( if (inputVariable < 100) ), it sets the variable if it passes the test ( inputVariable = 100 ), and it uses the value of the variable as an input to the delay() function ( delay(inputVariable) )

to:

delay(inputVariable2);@]

This example shows all three useful operations with variables. It tests the variable ( if (inputVariable2 < 100) ), it sets the variable if it passes the test ( inputVariable2 = 100 ), and it uses the value of the variable as an input to the delay() function ( delay(inputVariable2) )

September 06, 2008, at 08:58 PM by Paul Badger -
Deleted line 12:
Changed lines 18-19 from:

Once variables have been declared, they are used by setting the variable equal to the value one wishes to store with the assignment operator (single equal sign). The assignment operator tells the program to put whatever is on the left side of the equal sign into the variable on the right side.

to:

Once variables have been declared, they are used by setting the variable equal to the value one wishes to store with the assignment operator (single equal sign). The assignment operator tells the program to put whatever is on the right side of the equal sign into the variable on the left side.

Changed lines 25-28 from:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code.

Once a variable has been set (or re-set), you can test its value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable is less than 100, then sets a delay based on inputVariable which is a minimum of 100:

to:

Example

Once a variable has been set (or re-set), you can test its value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable2 is less than 100, then sets a delay based on inputVariable2 which is a minimum of 100:

September 06, 2008, at 08:53 PM by Paul Badger -
Changed lines 7-10 from:

Before they are used, all variables have to be declared. Declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). Variables do not have to be intialized (assigned a value) when they are declared, but it is often useful.

Programmers should consider the size of the numbers they wish to store in choosing variable types. Also the specific place that variables are declared influences how the program will 'see' the variable. This is called variable scope.

to:

Before they are used, all variables have to be declared. Declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). Variables do not have to be initialized (assigned a value) when they are declared, but it is often useful.

Programmers should consider the size of the numbers they wish to store in choosing variable types. Also the specific place that variables are declared influences how the program will see the variable. This is called variable scope.

September 06, 2008, at 08:51 PM by Paul Badger -
Changed line 11 from:

[=

to:

[@

Changed lines 15-17 from:

=]

to:

@]

September 06, 2008, at 08:51 PM by Paul Badger -
Changed lines 23-24 from:

inputVariable2 = analogRead(2); // set the variable named inputVariable2 to the (digitized) input voltage read from analog pin #2@]

to:

inputVariable2 = analogRead(2); // sets the variable named inputVariable2 to the

                                // (digitized) input voltage read from analog pin #2@]
September 06, 2008, at 08:50 PM by Paul Badger -
Changed lines 22-24 from:

inputVariable1 = 7; // sets the inputVariable1 to 7 inputVariable1 = analogRead(2); // set the variable to the (digitized) input voltage of analog pin #2@]

to:

inputVariable1 = 7; // sets the variable named inputVariable1 to 7 inputVariable2 = analogRead(2); // set the variable named inputVariable2 to the (digitized) input voltage read from analog pin #2@]

September 06, 2008, at 08:49 PM by Paul Badger -
Changed lines 5-6 from:

Variables are used by setting them equal to the value one wishes to store with the assignment operator (single equal sign). The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

to:

Declaring Variables

Before they are used, all variables have to be declared. Declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). Variables do not have to be intialized (assigned a value) when they are declared, but it is often useful.

Programmers should consider the size of the numbers they wish to store in choosing variable types. Also the specific place that variables are declared influences how the program will 'see' the variable. This is called variable scope.

int inputVariable1; int inputVariable2 = 0; // both are correct

Using Variables

Once variables have been declared, they are used by setting the variable equal to the value one wishes to store with the assignment operator (single equal sign). The assignment operator tells the program to put whatever is on the left side of the equal sign into the variable on the right side.

Changed lines 22-24 from:

int inputVariable = 0; // declares the variable; this only needs to be done once inputVariable = analogRead(2); // set the variable to the input of analog pin #2@]

to:

inputVariable1 = 7; // sets the inputVariable1 to 7 inputVariable1 = analogRead(2); // set the variable to the (digitized) input voltage of analog pin #2@]

Changed lines 43-50 from:

Variable Declaration

All variables have to be declared before they are used. Declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). In the above example, the statement

int inputVariable = 0;

to:
September 06, 2008, at 08:36 PM by Paul Badger -
Changed lines 5-6 from:

You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

to:

Variables are used by setting them equal to the value one wishes to store with the assignment operator (single equal sign). The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

September 06, 2008, at 02:39 AM by Paul Badger -
Changed lines 5-8 from:

A value is stored in a variable by assigning a value to it with the equal sign [=] ( single equal sign more formally called the assignment operator.

The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

to:

You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

Changed lines 11-12 from:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code.

to:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code.

September 06, 2008, at 02:38 AM by Paul Badger -
Changed lines 5-6 from:

You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

to:

A value is stored in a variable by assigning a value to it with the equal sign [=] ( single equal sign more formally called the assignment operator.

The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

Changed lines 13-14 from:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code.

to:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code.

July 17, 2007, at 06:44 AM by Paul Badger -
Changed lines 27-28 from:

You can name a variable any word that is not already one of the keywords? in Arduino.

to:

You can name a variable any word that is not already one of the keywords? in Arduino. Avoid beginning variable names with numeral characters.

Added line 42:
July 17, 2007, at 06:42 AM by Paul Badger -
Changed lines 31-32 from:

All variables have to be declared before they are used. Declaring a variable means defining its type, and setting an initial value. In the above example, the statement

to:

All variables have to be declared before they are used. Declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). In the above example, the statement

June 22, 2007, at 02:20 PM by Paul Badger -
Changed line 18 from:
  inputVariable = 100
to:
  inputVariable = 100;
Changed lines 21-22 from:

delay(inputVariable)@]

to:

delay(inputVariable);@]

May 27, 2007, at 02:38 AM by Paul Badger -
Changed line 43 from:
to:
Changed line 45 from:
to:
May 27, 2007, at 02:37 AM by Paul Badger -
Added line 43:
Added lines 45-47:
May 27, 2007, at 02:35 AM by Paul Badger -
Changed lines 8-10 from:

int inputVariable = 0; # Declares the variable; this only needs to be done once inputVariable = analogRead(2); # Set the variable to the input of analog pin #2@]

to:

int inputVariable = 0; // declares the variable; this only needs to be done once inputVariable = analogRead(2); // set the variable to the input of analog pin #2@]

April 16, 2007, at 04:22 PM by Paul Badger -
Changed lines 1-2 from:

Variables

to:

Variables

Deleted lines 43-44:
March 31, 2006, at 04:00 AM by Tom Igoe -
Changed lines 13-14 from:

Once a variable has been set (or re-set), you can test it's value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable (from analog pin #2) is less than 100, then sets a delay based on inputVariable which is a minimum of 100:

to:

Once a variable has been set (or re-set), you can test its value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable is less than 100, then sets a delay based on inputVariable which is a minimum of 100:

March 31, 2006, at 04:00 AM by Tom Igoe -
Changed lines 9-10 from:

inputVariable = analogRead(2); # Set the variable@]

to:

inputVariable = analogRead(2); # Set the variable to the input of analog pin #2@]

March 31, 2006, at 03:59 AM by Tom Igoe -
Changed lines 3-4 from:

A variable is a way of naming and storing a value for later use by the program. An example of , like data from a analog pin set to input. (See pinMode for more on setting pins to input or output.)

to:

A variable is a way of naming and storing a value for later use by the program, such as data from a analog pin set to input. (See pinMode for more on setting pins to input or output.)

March 31, 2006, at 03:58 AM by Tom Igoe -
Changed lines 11-12 from:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value at analog pin #2 is greater than 0:

to:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code.

Once a variable has been set (or re-set), you can test it's value to see if it meets certain conditions, or you can use it's value directly. For instance, the following code tests whether the inputVariable (from analog pin #2) is less than 100, then sets a delay based on inputVariable which is a minimum of 100:

Changed line 16 from:

if (inputVariable > 0)

to:

if (inputVariable < 100)

Changed lines 18-22 from:
  # do something here

}@]

You should give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value, on the other hand, do little to make your code readable.

to:
  inputVariable = 100

}

delay(inputVariable)@]

This example shows all three useful operations with variables. It tests the variable ( if (inputVariable < 100) ), it sets the variable if it passes the test ( inputVariable = 100 ), and it uses the value of the variable as an input to the delay() function ( delay(inputVariable) )

Style Note: You should give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value, on the other hand, do little to make your code readable.

March 31, 2006, at 03:49 AM by Tom Igoe -
Changed lines 8-10 from:

int inputVariable = 0; # This declares the variable, declaration only needs to be done once inputVariable = analogRead(2); # This sets the variable@]

to:

int inputVariable = 0; # Declares the variable; this only needs to be done once inputVariable = analogRead(2); # Set the variable@]

March 31, 2006, at 03:48 AM by Tom Igoe -
Changed lines 5-6 from:
 You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:
to:

You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

March 31, 2006, at 03:48 AM by Tom Igoe -
Changed lines 3-6 from:

Variables are expressions that store values, like sensor reading and storing input from a analog pin set to input. (See pinMode for more on setting pins to input or output.)

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

to:

A variable is a way of naming and storing a value for later use by the program. An example of , like data from a analog pin set to input. (See pinMode for more on setting pins to input or output.)

 You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:
Changed lines 8-10 from:

int inputVariable = 0; inputVariable = analogRead(2);@]

to:

int inputVariable = 0; # This declares the variable, declaration only needs to be done once inputVariable = analogRead(2); # This sets the variable@]

March 31, 2006, at 02:45 AM by Tom Igoe -
Changed lines 11-12 from:

inputVariable is the variable itself. The first line declares that it will contain an int, which is to say a whole number. The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value at analog pin #2 is greater than 0:

to:

inputVariable is the variable itself. The first line declares that it will contain an int (short for integer.) The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value at analog pin #2 is greater than 0:

Changed lines 25-26 from:

All variables have to be declared before they are used. To declare a variable implies to define its type, and an initial value.

to:

All variables have to be declared before they are used. Declaring a variable means defining its type, and setting an initial value. In the above example, the statement

Changed line 28 from:

int val = 0;

to:

int inputVariable = 0;

Changed lines 31-32 from:

The previous statement informs that the variable val is of the type int and that its initial value is zero.

to:

declares that inputVariable is an int, and that its initial value is zero.

Added line 35:
Deleted line 36:
March 30, 2006, at 10:24 PM by Tom Igoe -
Changed lines 19-20 from:

You should give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value do little to make your code readable.

to:

You should give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value, on the other hand, do little to make your code readable.

March 30, 2006, at 10:11 PM by Tom Igoe -
Changed lines 37-38 from:
to:
March 30, 2006, at 10:11 PM by Tom Igoe -
March 30, 2006, at 10:11 PM by Tom Igoe -
Changed lines 11-12 from:

inputVariable is the variable itself. The first line declares that it will contain an int, which is to say a whole number. The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value of inputVariable is greater than 0:

to:

inputVariable is the variable itself. The first line declares that it will contain an int, which is to say a whole number. The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value at analog pin #2 is greater than 0:

March 30, 2006, at 10:00 PM by Tom Igoe -
Changed lines 9-11 from:

inputVariable = analogRead(2); @]

to:

inputVariable = analogRead(2);@]

Changed lines 17-18 from:

} @]

to:

}@]

March 30, 2006, at 09:59 PM by Tom Igoe -
Changed lines 20-22 from:

You give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value do little to make your code readable.

to:

You should give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value do little to make your code readable.

March 30, 2006, at 09:59 PM by Tom Igoe -
Changed lines 5-6 from:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code sets inputVariable equal to the value at analog pin #2:

to:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code declares a variable inputVariable, and then sets it equal to the value at analog pin #2:

Changed line 8 from:

int inputVariable;

to:

int inputVariable = 0;

Changed lines 12-13 from:

input_variable is the variable itself. The first line declares that it will contain an int, which is to say a whole number. The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value of inputVariable is greater than 0:

to:

inputVariable is the variable itself. The first line declares that it will contain an int, which is to say a whole number. The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value of inputVariable is greater than 0:

Changed lines 23-26 from:

You can choose any word that is not already existing in the language. The pre-defined words in the language are also called keywords. Examples of keywords are: digitalRead, pinMode, or setup.

Again it is possible to choose completely random names like tomato or I_love_Sushi but this will make much more complicated for other people to read your code and it is not recommended. Use variable names that describe what you're using them for, like sensorValue or switchState.

to:

You can name a variable any word that is not already one of the keywords? in Arduino.

Changed lines 27-28 from:

Variables have to be declared before they are used. To declare a variable implies to define its type, and an initial value.

to:

All variables have to be declared before they are used. To declare a variable implies to define its type, and an initial value.

March 30, 2006, at 09:52 PM by Tom Igoe -
Changed line 7 from:

[=

to:

[@

Changed lines 10-11 from:

=]

to:

@]

Changed line 14 from:

[=

to:

[@

Changed lines 19-20 from:

=]

to:

@]

March 30, 2006, at 09:52 PM by Tom Igoe -
Changed line 8 from:

int inputVariable;\\

to:

int inputVariable;

Changed lines 15-17 from:

if (inputVariable > 0)
{
# do something here\\

to:

if (inputVariable > 0) {

  # do something here
March 30, 2006, at 09:52 PM by Tom Igoe -
Changed line 8 from:

int inputVariable;

to:

int inputVariable;\\

Changed lines 15-17 from:

if (inputVariable > 0) {

  # do something here
to:

if (inputVariable > 0)
{
# do something here\\

March 30, 2006, at 09:51 PM by Tom Igoe -
Changed lines 5-6 from:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code sets input_variable equal to the value at analog pin #2:

to:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code sets inputVariable equal to the value at analog pin #2:

Changed lines 8-9 from:

input_variable = analogRead(2);

to:

int inputVariable; inputVariable = analogRead(2);

Changed lines 12-21 from:

input_variable is the variable itself; it makes the value at analog pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value of input_variable is The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

You can choose any word that is not already existing in the language. The pre-defined words in the language are also called keywords. Examples of keywords are: digitalRead, pinMode, or setup.

Again it is possible to choose completely random names like tomato or I_love_Sushi but this will make much more complicated for other people to read your code and it is not recommended. Use variable names that describe what you're using them for, like sensorValue or switchState.

Variable Declaration

Variables have to be declared before they are used. To declare a variable implies to define its type, and an initial value.

to:

input_variable is the variable itself. The first line declares that it will contain an int, which is to say a whole number. The second line sets inputVariable to the value at analog pin #2. This makes the value of pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value of inputVariable is greater than 0:

Changed lines 15-18 from:

int val = 0;

to:

if (inputVariable > 0) {

  # do something here

}

Added lines 21-34:

You give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value do little to make your code readable.

You can choose any word that is not already existing in the language. The pre-defined words in the language are also called keywords. Examples of keywords are: digitalRead, pinMode, or setup.

Again it is possible to choose completely random names like tomato or I_love_Sushi but this will make much more complicated for other people to read your code and it is not recommended. Use variable names that describe what you're using them for, like sensorValue or switchState.

Variable Declaration

Variables have to be declared before they are used. To declare a variable implies to define its type, and an initial value.

int val = 0;

March 30, 2006, at 09:37 PM by Tom Igoe -
Changed lines 5-6 from:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code sets input_variable equal to the value at analog pin #2.:

to:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code sets input_variable equal to the value at analog pin #2:

Changed lines 11-12 from:

input_variable is what's called a variable. It is a container for data inside the memory of Arduino. The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

to:

input_variable is the variable itself; it makes the value at analog pin #2 accessible elsewhere in the code. For instance, the following code tests whether the value of input_variable is The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

March 30, 2006, at 09:35 PM by Tom Igoe -
Added lines 5-6:

A variable is a way of giving a name to the stored value. You set a variable by making it equal to the value you want to store. The following code sets input_variable equal to the value at analog pin #2.:

Changed line 8 from:

val = analogRead(2);

to:

input_variable = analogRead(2);

Changed lines 11-12 from:

val is what's called a variable. It is a container for data inside the memory of Arduino. The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

to:

input_variable is what's called a variable. It is a container for data inside the memory of Arduino. The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

March 30, 2006, at 09:32 PM by Tom Igoe -
Changed lines 3-4 from:

Variables are expressions that can be used in programs to store values, like e.g. sensor reading from an analog pin.

to:

Variables are expressions that store values, like sensor reading and storing input from a analog pin set to input. (See pinMode for more on setting pins to input or output.)

March 25, 2006, at 07:18 AM by Jeff Gray -
Changed lines 1-2 from:

Variables

to:

Variables

March 25, 2006, at 06:32 AM by Tom Igoe -
Changed lines 9-10 from:

val is what we call a variable. It is a container for data inside the memory of Arduino. The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

to:

val is what's called a variable. It is a container for data inside the memory of Arduino. The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

Changed lines 13-14 from:

Again it is possible to choose completely random names like tomato or I_love_Sushi but this will make much more complicated for other people to read your code and it is not recommended.

to:

Again it is possible to choose completely random names like tomato or I_love_Sushi but this will make much more complicated for other people to read your code and it is not recommended. Use variable names that describe what you're using them for, like sensorValue or switchState.

January 13, 2006, at 12:34 AM by 82.186.237.10 -
Changed lines 23-24 from:

The previous statement informs that the variable val is of the type Integer and that its initial value is zero.

to:

The previous statement informs that the variable val is of the type int and that its initial value is zero.

Changed lines 27-29 from:
to:
December 09, 2005, at 06:58 PM by 195.178.229.25 -
Added lines 1-29:

Variables

Variables are expressions that can be used in programs to store values, like e.g. sensor reading from an analog pin.

val = analogRead(2);

val is what we call a variable. It is a container for data inside the memory of Arduino. The name of the variable is val in this case, but we could have chosen anything else like e.g. inputPin or sensorA.

You can choose any word that is not already existing in the language. The pre-defined words in the language are also called keywords. Examples of keywords are: digitalRead, pinMode, or setup.

Again it is possible to choose completely random names like tomato or I_love_Sushi but this will make much more complicated for other people to read your code and it is not recommended.

Variable Declaration

Variables have to be declared before they are used. To declare a variable implies to define its type, and an initial value.

int val = 0;

The previous statement informs that the variable val is of the type Integer and that its initial value is zero.

Possible types for variables are:

Share