Instructions
www.joy-it.net
Pascalstr. 8 47506 Neukirchen-Vluyn
5. LESSONS
Lesson 1 : Hello world
We start with something simple. For this project you only need the board
and a USB cable to start the lesson. This is a communication test for your
Mega2560 and your PC, and a basic project for your first try in the
Arduino world!
Once the installation of the drivers is complete, open the Arduino
soware and write a code that will allow the Mega2560 to display
Hel-
lo World!
under your instructions. Of course, you can also write a code
that will allow the Mega2560 to display
Hello World!
repeatedly with-
out prompting. A simple
if()
statement will do this. We can instruct the
LED on pin 13 to blink first and then display Hello World! aer the Ar-
duino gets the command to do so.
int val; // defines the variable “Val”
int ledpin=13; // defines the digital interface 13
void setup() {
Serial.begin(9600);
// sets the baudrate to 9600 to fit the software configuration
pinMode(ledpin,OUTPUT); // sets the digital pin 13 to output
}
void loop() {
val=Serial.read();
if(val=='R') { // checks if the character is a R.
// if so:
digitalWrite(ledpin,HIGH); // turns on LED
delay(500);
digitalWrite(ledpin,LOW); // turns off LED
delay(500);
Serial.println("Hello World!"); // Shows „Hello World!”.
}
}