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

  • 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
  • Powerful Essays

    EAS230Syllabus

    • 1748 Words
    • 8 Pages

    C++ programming: editing, compiling, user I/O, variables (ints, doubles, char, strings, booleans), loops, decisions, functions, pointers, arrays, tables, databases, sorting.…

    • 1748 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    3. When a module is executing, what happens when the end of the module is reached?…

    • 765 Words
    • 5 Pages
    Satisfactory 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

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    1) Initialization: the variable is initialized 2) Test: the loop tests the variable by comparing it to the maximum value 3) Increment: to increase the value during each iteration the loop increments the counter variable by adding 1 to it.…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1310 Unit 1

    • 4209 Words
    • 17 Pages

    If two steps are indented at the same level, the uppermost statement is executed first. ans)All of the above…

    • 4209 Words
    • 17 Pages
    Powerful Essays
  • Satisfactory Essays

    Lab 7 Student

    • 1242 Words
    • 7 Pages

    A condition-controlled loop uses a true/false condition to control the number of times that it repeats.…

    • 1242 Words
    • 7 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
  • Satisfactory Essays

    I Like to 1321

    • 459 Words
    • 2 Pages

    statement. Also included is a for loop (repetition statement). Pay close attention to these as you…

    • 459 Words
    • 2 Pages
    Satisfactory 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
  • 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
  • Good Essays

    Reusability of Code

    • 511 Words
    • 3 Pages

    The earliest programming languages were procedural, meaning a program was made of one or more procedures. A procedure is simply a module or function that performs a specific task such as gathering input from the user, performing calculations, reading or writing files, displaying output, and so on. The programs that you have written so far have been procedural in nature. The steps a program must perform to reach the desired outcome. Procedure is an independent entity and a sequence of instructions that are grouped together. In procedural programming, a task is broken down into assortment of variables and subroutines. In OPP, a task is broken down into objects which summarize the data and execution. In a procedural approach, the entirely called variable is termed as a trait of the object. The idea is to encapsulate data and a…

    • 511 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Unit 7 Assignment 1

    • 749 Words
    • 4 Pages

    What are three actions do count-controlled loop typically performed using the counter variable? Initialization, Test, Increment…

    • 749 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    The expression 1 To 5 in the Case 1 To 5 clause specifies the range of numbers from ____.…

    • 595 Words
    • 3 Pages
    Satisfactory 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