Reader small image

You're reading from  Arduino Development Cookbook

Product typeBook
Published inApr 2015
Publisher
ISBN-139781783982943
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Cornel M Amariei
Cornel M Amariei
author image
Cornel M Amariei

Cornel Amariei is a Romanian inventor and entrepreneur in the fields of Robotics and 3D printing. He has been working with the Arduino platform since its early days in 2007. His past experience involves large cargo gamma ray scanning robotics, ATM security systems, and blind assisting devices. In his spare time, he is a performing musician playing multiple instruments—predominately the guitar. He is also a swimmer, water polo player, and photographer. Over the years, he has built hundreds of Arduino projects, ranging from flying Quadcopters to levitating magnets and underwater robots. Currently, he splits his time between doing his undergraduate studies in electric engineering and computer science at Jacobs University in Bremen, Germany, and his start-ups and research and development job.
Read more about Cornel M Amariei

Right arrow

Learning Arduino code basics


Here we begin with the basics of coding for Arduino. Writing code for Arduino and other embedded platforms is a little different from writing code for a computer. But don't fear—the differences are small.

Getting ready

To execute this recipe, we need just one ingredient: the Arduino IDE running on a computer.

How to do it…

These are the two mandatory functions in the Arduino coding environment:

void setup() {
  // Only execute once when the Arduino boots
}


void loop(){
  // Code executes top-down and repeats continuously
}

How it works…

Each Arduino sketch has two mandatory functions: the setup() function and the loop() function. The setup() function only executes once: either when we apply power to the Arduino or when it resets. Usually, we use this function to configure the pins of the Arduino, to start communication protocols, such as serial communication, or to perform actions we only want to perform once when the Arduino boots.

The loop() function executes continuously. Code in this function is executed top-down; when it reaches the end of the function, it jumps back to the start and runs again. This happens forever until the Arduino is switched off. In here, we write the code we want to run continuously.

See also

Continue the Arduino code basics with the following recipe, Code basics: Arduino C.

Previous PageNext Page
You have been reading a chapter from
Arduino Development Cookbook
Published in: Apr 2015Publisher: ISBN-13: 9781783982943
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Cornel M Amariei

Cornel Amariei is a Romanian inventor and entrepreneur in the fields of Robotics and 3D printing. He has been working with the Arduino platform since its early days in 2007. His past experience involves large cargo gamma ray scanning robotics, ATM security systems, and blind assisting devices. In his spare time, he is a performing musician playing multiple instruments—predominately the guitar. He is also a swimmer, water polo player, and photographer. Over the years, he has built hundreds of Arduino projects, ranging from flying Quadcopters to levitating magnets and underwater robots. Currently, he splits his time between doing his undergraduate studies in electric engineering and computer science at Jacobs University in Bremen, Germany, and his start-ups and research and development job.
Read more about Cornel M Amariei