Operácie

Acrob002

Z SensorWiki

< Previous | Home | Next >

Hello, World!

ArduinoIDE01.png

Here is a source code for Your first program.

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 Serial.println("Hello, World!");
}

It should look like on the screen right.


To run the program on Your board it is necessary to compile and download the program using the ArduinoButtonUpload.png button. If the operation was successfull, the downloaded program runs automatically. To see how it works, it is necessary to open an additional window with the terminal ArduinoButtonTerminal.png.

It will look like this:

ArduinoIDE02.png

How it works

Notice that program contains two blocks. Section setup() runs just once, during the startup. Usually contains settings, definitions and hardware initialization and configuration commands.

Then the program performs an infinity loop(). There is defined the whole operation of Your program.

  • Why there is not just single Hello, World! message?

This is because the print command is located in the loop() section.

  • But I want to have just ONE message!

Well, why not. You can
 a) place the print command into the setup() section and leave the loop() empty.
 b) stop the loop using e.g following construction:

void loop()
{
 Serial.println("Hello, World!");
 for(;;);  /* stop here */
}

More commands

If You just want to verify Your program, You can just compile it ArduinoButtonCompile.png without downloading to Your board.

Don't forget to save Your work often using the ArduinoButtonSave.png button.


When You need a particular help with any Arduino language commands, use the menu item Help -> Reference. This is Your language handbook and wocabulary.

Nobody is perfect!

Try to intentionally make some mistakes in Your source code to see what happens and how the compiler lets You know what is the problem. The most often errors are

  • forgotten command terminator ';'
  • unmatched parentheses '{' and '}' and strings '" "'
  • misspelled commands (e.g. vood instead of void)
  • unknown comands (e.g. Serial.clearscreen() )

Your turn

  • Change the text of the message, add more messages, try to format them using special chars like '***' or '---'
  • What happens if You use the Serial.print() command instead of the Serial.println()?
  • TODO: Variables - declaration, using, types, display values...
< Previous | Home | Next >