Preview

Arduino Handbook

Better Essays
Open Document
Open Document
1883 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Arduino Handbook
structure

The basic structure of the Arduino programming language is fairly simple and runs in at least two parts. These two required parts, or functions, enclose blocks of statements.

void setup()

{

statements;

}

void loop()

{

statements;

}

Where setup() is the preparation, loop() is the execution. Both functions are required for the program to work.

The setup function should follow the declaration of any variables at the very beginning of the program. It is the first function to run in the program, is run only once, and is used to set pinMode or initialize serial communication.

The loop function follows next and includes the code to be executed continuously – reading inputs, triggering outputs, etc. This function is the core of all Arduino programs and does the bulk of the work.

setup()

The setup() function is called once when your program starts. Use it to initialize pin modes, or begin serial. It must be included in a program even if there are no statements to run.

void setup()

{

pinMode(pin, OUTPUT); // sets the 'pin' as output

}

loop()

After calling the setup() function, the loop() function does precisely what its name suggests, and loops consecutively, allowing the program to change, respond, and control the Arduino board.

void loop()

{

digitalWrite(pin, HIGH); // turns 'pin' on

delay(1000); // pauses for one second

digitalWrite(pin, LOW); // turns 'pin' off

delay(1000); // pauses for one second

}

functions

A function is a block of code that has a name and a block of statements that are executed when the function is called. The functions void setup() and void loop() have already been discussed and other built-in functions will be discussed later.

Custom functions can be written to perform repetitive tasks and reduce clutter in a program. Functions are declared by first declaring the function type. This is the type of value to be

You May Also Find These Documents Helpful

  • Good Essays

    Declares > this is the statements that declare variables, constants, and other code elements, which can then be used within that block…

    • 193 Words
    • 1 Page
    Good Essays
  • Satisfactory Essays

    Nt1330 Unit 2 Assignment 1

    • 3740 Words
    • 15 Pages

    1. A while loop will not execute the body of the code if you have your test condition incorrect.…

    • 3740 Words
    • 15 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Homework Unit 3

    • 354 Words
    • 2 Pages

    1. Statements are execute in order according to the program code. Complex programs can need the help of a decision structure. Statements have to be true to be executed.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Unit 59 Assignment 3

    • 645 Words
    • 3 Pages

    The process of how the subroutine works within an operating environment is as follows. While the main part of the program is running, there will be a call command sent to the CPU to tell it to stop wherever the program is at, store the W, Z and status along with where in the main program the CPU is at in the stack. Then the main program is cleared from memory and the subroutine is loaded for the CPU to start processing the code. Once the subroutine has finished, the subroutine code is deleted from memory and the CPU will load up the main program back on and will retrieve from stack the stored information (W, Z and status) which will allow the CPU know exactly where it needs to start from.…

    • 645 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    unit 7 assignment 1

    • 431 Words
    • 2 Pages

    5. What three actions do count-controlled loops typically perform using the counter variable? Initialization: Before the loop begins, the counter variable is initialized to a starting value. Test : The loop tests the counter variable by comparing it to a maximum value. If the counter variable is less than or equal to the maximum, the loop iterates. If the counter is greater than the maximum value, the program exits the loop. Increment : To increment a variable means to increase its value. During each iteration, the loop increments the counter variable by adding a predetermined amount to it…

    • 431 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Unit 3 network discovery

    • 1031 Words
    • 5 Pages

    The shell tries to find an executable program with the same name as the command. When it does, the shell executes the program. When finishing the command put an & ampersand symbol at the end of the command and the command will run in the background. Then a cursor will be displayed immediately to allow the next command to be entered.…

    • 1031 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Cis 207 Week 2/3 Quiz

    • 383 Words
    • 2 Pages

    * C. Follows the instructions as they appear in the program, whether they are right or wrong…

    • 383 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Homework Week 2

    • 743 Words
    • 3 Pages

    A compiler translates one computer language into another. It also pics up errors in the program being put together.…

    • 743 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    En1320 Unit 1 Research Paper 1

    • 27742 Words
    • 111 Pages

    computation are stored in registers R1 and R2, and the result of the computation is stored…

    • 27742 Words
    • 111 Pages
    Powerful Essays
  • Good Essays

    Unit 16 Ao1

    • 529 Words
    • 3 Pages

    Programs need to store data at some time during the execution of processes. Data is held in variables which are names containers for each piece of data. Each variable must be given a name so it can be referred to again and again throughout the program. It should be something that is recognisable because for example variable 1 would be soon forgotten in a substantial piece of code. Variable names cannot be the same as code words such as print or run.…

    • 529 Words
    • 3 Pages
    Good Essays
  • Better Essays

    2) The header is the starting point and the body is a list of statements that belong to the module.…

    • 1580 Words
    • 11 Pages
    Better Essays
  • Good Essays

    Compter Science

    • 819 Words
    • 4 Pages

    Programming statements in a low-level language will be close to natural language and will use standard mathematical notation.…

    • 819 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Intro the Programming

    • 386 Words
    • 5 Pages

    The ________ is a collection of statements enclosed inside a set of curly braces that are performed when the method is…

    • 386 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    A function is a relation in which each element of the domain is paired with exactly one element in the range. Two types of functions are the exponential functions and the logarithmic functions. Exponential functions are the functions in the form of y = ax, where ''a'' is a positive real number, greater than zero and not equal to one. Logarithmic functions are the inverse of exponential functions, y = loga x, where ''a'' is greater to zero and not equal to one. These functions have certain differences as well as similarities between them. Also they are very useful for various situations in life.…

    • 853 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    4 . When a program or module uses another module, you can refer to the main program as the ____ program.…

    • 2498 Words
    • 10 Pages
    Satisfactory Essays