Monday, August 1, 2016

Basic Structure of Arduino Programming Language


The basic structure of the Arduino Programming Language is fairly simple and runs in atleast two parts. These two required parts or functions enclose blocks of statement.


setup()
The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each power up or reset of the Arduino board.



loop()After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.

Both functions are required for the program to work.

 


12 comments:

  1. Back when I was 2nd Year College I had a Programming subject, and we used C++, so i'm not familiar with the Arduino. So what do you think is the difference between these two Programming languages?

    ReplyDelete
  2. Thank you for asking Karen.
    In theory...
    There isn't really an Arduino language as such. It's really just C++ with some domain-specific libraries. These add on various features, such as functions you can call to control the hardware. If you didn't have those functions, you'd need to fiddle directly with special registers to control everything. That's how embedded programming is usually done. It's fast, but it can be quite hard to learn and understand.

    In addition to the functions, the libraries add alternative names for some types. For example, boolean and byte are not in the C++ standard. However, they are directly equivalent to bool and unsigned char.

    All of these things mean you can probably port general C++ code directly to Arduino without difficulty. However, going back the other way may require some minor editing.

    In practice...
    Having said all of that, programming for Arduino isn't exactly the same as general C++ programming. A lot of the differences are common to all embedded programming though (such as limited memory and processing power).

    It's also worth noting that if you're using the official Arduino IDE then there are all sorts of annoying quirks and limitations on how you setup your code.

    I hope I answered your question.

    ReplyDelete
  3. Hi Ma'am Mica, I'm just wondering about arduino module. I am currently using TM-1 module for programming my IC AT89C2051. Is it possible for me to use arduino module for programming my IC AT89C2051?

    ReplyDelete
    Replies
    1. Sorry I got confused. Did you mean you want to program AT89C2051 in Arduino Board but still using the atmel programmer?

      Delete
    2. Hmm, no mam I want to programm AT89C2051 in the Arduino board using arduino programmer.

      Delete
    3. It's kinda complicated Marvin. But the good thing is that someone has already did it. But Arduino Mega 2560 Board is used instead of the Arduino Uno Board.

      To see the actual process, go to http://ceptimus.co.uk/?p=216

      Delete
  4. Hi Maam Mica. When and where is arduino programming language applicable to use?

    ReplyDelete
    Replies
    1. Thanks for asking Jolina. :) Arduino programming language has been used in thousands of different projects and applications. The Arduino Software (IDE) runs runs on Mac, Windows, and Linux. Teachers and students use it to build low cost scientific instruments, to prove chemistry and physics principles, or to get started with programming and robotics. Designers and architects build interactive prototypes, musicians and artists use it for installations and to experiment with new musical instruments. Makers, of course, use it to build many of the projects exhibited at the Maker Faire, for example. Arduino is a key tool to learn new things. Anyone - children, hobbyists, artists, programmers - can start tinkering just following the step by step instructions of a kit, or sharing ideas online with other members of the Arduino community.

      Read more: https://www.arduino.cc/en/Guide/Introduction

      Delete
  5. Ma'am Micah, how different arduino language than Atmel language?

    ReplyDelete
    Replies
    1. Thanks for asking Katrina. The language is the same. The available symbols are different. You can either use Arduino IDE or Atmel Studio.The Arduino libary is more of a wrapper to make it easy to do things, like digitalWrite, which you do not have by default in Atmel Studio. Hope this one answered your question.

      For further reading, go to http://electronics.stackexchange.com/questions/84593/how-different-is-the-arduino-language-than-atmel-studio-language.

      Delete
  6. hi ma'am micah, aside form "void setup ()",there are other arduino codes that can initialize pin codes or begin serial to begin the preparation of the program??

    ReplyDelete
    Replies
    1. Glad you asked Genet. Void setup is the only function that can initialize the pin codes or begin the serial when you are using the Arduino Software (IDE).

      Delete