Download Print this page

Intel Galileo Hardware Manual page 16

Biobots
Hide thumbs Also See for Galileo:

Advertisement

Hardware
This reads a value from pin
We have to create a variable, which we can later do something with. A
a value. In this case it is a number and can be changed and used later in the program.
The microcontroller has to be told what the name of the variable is, and what it will be used for. That is done
by writing something called a
will go at the beginning of the
int myVariable;
This tells the Galileo that you want a variable which is named '
ger
, which is any whole number, including zero, positive, and negative numbers.
You can name your variable anything, you just have to make sure you type it the exact same way every time.
myVariable
For example, '
spaces in the variable.
After we tell the microcontroller that we have a variable, we have to assign it a value. This can be done by us-
analogRead
ing the value from
myVariable = analogRead(A0);
So, the whole program would look like this:
void setup(){
variable
loop
Now, each time the
myVariable
will be a high number (around 1000) if the sensor is at one extreme (turned all the way, in a
very bright environment, pushed down) and around 0 if the sensor is at the other extreme.
3.6: Using analogWrite
The simplest thing that can now be done with
ing for this is the same as in Lesson 2.
Controlling an LED requires us to use
analogWrite
put, and to use
A0
. However, it doesn't do anything with the value.
declaration
. In this case our declaration will look something like this, which
loop
routine:
' is not the same as '
. You can tell the Galileo to assign a value to a variable using an equal sign:
pinMode(A0, INPUT); //analog input
}
void loop(){
int myVariable; //declare variable
myVariable = analogRead(A0); //assign
}
myVariable
goes through,
myVariable
pinMode
to write to the LED.
myVariable
myvariable
'. Also, the microcontroller won't understand
will be assigned whatever the analog pin is sensing.
is to control the brightness of an LED. The wir-
to tell the microcontroller we are using same pin as an out-
variable
is something that can hold
' and you will use it as a
inte-
Hardware 16

Advertisement

loading