Digitalwrite; Delay - Arduino uno User Manual

Hide thumbs Also See for uno:
Table of Contents

Advertisement

delay(100);

}
You may have noticed when trying this out that if you leave one of the pins disconnected, its
state follows the other. This is because a pin left floating has an undefined value and will wander
from high to low. So, use two jumper wires when trying out this example.
Here's one that checks the value of a variable after an addition. Because the calculation is done
just once, all the code is in the setup() function. The Serial.flush()
int i,j,k;
void setup()
{
Serial.begin(9600);
i=21;
j=20;
k=i+j;
Serial.flush();
Serial.print(k);
}
void loop() {}

digitalWrite

This command sets an I/O pin high (+5V) or low (0V) and is the workhorse for commanding the
outside world of lights, motors, and anything else interfaced to your board. Use the pinMode()
command in the setup() function to set the pin to an output.
digitalWrite(2,HIGH);
digitalWrite(2,LOW);
delay
Delay pauses the program for a specified number of milliseconds. Since most interactions with
the world involve timing, this is an essential instruction. The delay can be for 0 to 4,294,967,295
msec. This code snippet turn on pin 2 for 1 second.
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
if
This is the basic conditional branch instruction that allows your program to do two different
things depending on whether a specified condition is true or false.
Here is one way to have your program wait in place until a switch is closed. Connect a switch to
pin 3 as shown in Section 3. Upload this program then try closing the switch
void setup()
// sets pin 2 to +5 volts
// sets pin 2 to zero volts
// pin 2 high (LED on)
// wait 500 ms
// pin 2 low (LED off)
21

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the uno and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents

Save PDF