Communications
Using the example code from before-
If the following line below is added inside of the setup() function, the serial port will be initialized with a baud rate of 9600-
With the Serial port initialized in the Setup() function as shown above, adding a few lines of code in the loop() function will result in the phrase 'Hello World' being printed to the Serial Monitor every 100 milliseconds-
One of the most valuable capabilities of an Arduino is the ability to communicate via the Serial Port. Every Arduino that connects to a computer through a USB(Universal Serial Bus) cable can communicate to download sketches, but it also can be used to let the processor communicate with the computer as well.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
The Serial Monitor and how to use it will be discussed on the next page. One important thing to note in the above code the line- 'delay(100);'. This is a call to a built-in function of Arduino that puts the processor on hold for the given amount of time in milliseconds. 'delay(1000);' would put the processor on hold for 1 second. Can you see why?
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello World");
delay(100);
}