Operácie

Acrob002: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Bez shrnutí editace
Balogh (diskusia | príspevky)
Bez shrnutí editace
 
(2 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.)
Riadok 1: Riadok 1:
== Hello, World! ==
[[Acrob001|< Previous]] | [[Acrob|Home]] | [[Acrob003|Next >]]
 
== '''Hello, World!''' ==




Riadok 48: Riadok 50:
{
{
  Serial.println("Hello, World!");
  Serial.println("Hello, World!");
  for(;;)  /* stop here */
  for(;;); /* stop here */
}
}
</source>
</source>
Riadok 58: Riadok 60:


Don't forget to save Your work often using the  [[Obrázok:ArduinoButtonSave.png|29px]] button.
Don't forget to save Your work often using the  [[Obrázok:ArduinoButtonSave.png|29px]] 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!'''
'''Nobody is perfect!'''
Riadok 73: Riadok 79:
* What happens if You use the Serial.print() command instead of the Serial.println()?
* What happens if You use the Serial.print() command instead of the Serial.println()?


*  
* TODO: Variables - declaration, using, types, display values...


  [[Acrob001|< Previous]] | [[Acrob|Home]] | [[Acrob003|Next >]]
  [[Acrob001|< Previous]] | [[Acrob|Home]] | [[Acrob003|Next >]]

Aktuálna revízia z 14:10, 12. jún 2010

< Previous | Home | Next >

Hello, World!

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 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 .

It will look like this:

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 without downloading to Your board.

Don't forget to save Your work often using the 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 >