Im reading Brian Evan's programming notebook ???
Page 9
int x = 13; //declares variable x as the integer 13 .... OK I think I understand ??
Page 10
int inputVariable = 0; // declares variable assigns value on 0 ...OK..
inputVariable = analogRead(2); // set variable to value of analog pin 2 ....Ok...
Page 22
int led = 13; //connect LED to pin 13 ?????
?? //why does this not just declare a variable called led and assign it the value of 13 as was on page 9.
int pin = 7; // connect pushbutton to pin 7 ????
int value = 0; //variable to store data....... this actually is a variable not a pin number ??
Basically.........
If I declare say int pin1=6; does it mean a variable assigned the value of 6 .... or does it mean pin1 uses the pin number6.
or int switchA=8; is it value 8 or pin 8.
Thanks
Confusing variables
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Confusing variables
He is just declaring variables and assigning them values so he can use symbolic names to represent pin numbers.
For example:
digitalWrite(led, HIGH);
is more explicit than
digitalWrite(13, HIGH);
For example:
digitalWrite(led, HIGH);
is more explicit than
digitalWrite(13, HIGH);
- baldengineer
- Posts: 127
- Joined: Sun Sep 26, 2010 11:49 pm
Re: Confusing variables
Your confusion is a great example of writing good comments... (Which these are not.) The comment suggests that the LED is physically connected to pin 13. This may be what happens in the hardware, but the software does not make any such connection for you. All that happens is that the variable "led" has a value of 13.hardada wrote:Im reading Brian Evan's programming notebook ???
int led = 13; //connect LED to pin 13 ?????
?? //why does this not just declare a variable called led and assign it the value of 13 as was on page 9.
int pin = 7; // connect pushbutton to pin 7 ????
This means later on in the code you can do this:
Code: Select all
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
Code: Select all
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Variables, by themself, have nothing to do with pin numbers. Variables store data. That's all.hardada wrote: int value = 0; //variable to store data....... this actually is a variable not a pin number ??
You created a variable called "pin1" which has the value of 6 (an integer.) Again, nothing explicitly to do with pins.hardada wrote: If I declare say int pin1=6; does it mean a variable assigned the value of 6 .... or does it mean pin1 uses the pin number6.
Please be positive and constructive with your questions and comments.