In this experiment we begin to learn the use of analog I/O interface, the Arduino has simulated 0-5 for a total of six simulation interface, the six interface can also be as interface function reuse, in addition to the analog interface functions, the six interface can be used as a digital interface, Numbers for digital 14-19, after simple understanding, below to begin our experiments, adjustable resistance is a typical simulated values of the people familiar with the output element, this experiment will use it to finish, the required components are:
Adjustable resistance * 1
Bread plate * 1
Bread board jumpers * 1 firm
This experiment we will adjustable resistance value is converted into analog value read out and then displayed on the screen, this is also our future experiments required to complete their function must grasp to instances of the application, we must first according to the following diagram connection object graph, we use the simulation interface of 0
After good circuit according to the below link, you can begin to write programs, borrowed from the Arduino digital reference program 13 built-in LED small lights, each read value small lights will blink,
Reference procedure is as follows:
Int potpin=0;//define simulation interface 0
Int ledpin=13;//define digital interface 13
Int val=0;//will define variable val and initialise 0
Void setup ()
{
PinMode (ledpin, the OUTPUT);//define digital interface for the output interface
Serial.begin(9600);//set the baud rate of 9600
}
Void loop ()
{
DigitalWrite (ledpin, HIGH);//13 LED light digital interface
delay(50);//0.05 seconds delay
DigitalWrite (ledpin, LOW);//out 13 LED digital interface
delay(50);//0.05 seconds delay
Val=analogRead (potpin);//read the value of the analog interface 0 and assigned to val
Serial. Println (val);//show the value of val
}
This experiment is done here, when you rotate the adjustable resistance knob can see the screen numerical changes, read the simulation value this method will always accompany us, read analog value is our common function, because a lot of sensors are simulated output value, we read the simulation value and then corresponding algorithm processing, can be applied to the function we need to implement,