If you're finding the Arduino Reference a bit dry you need this page.
On this Arduino reference page you can find links to common Arduino
functions so you can find out how they work, and how you should use
them. Some functions are obvious while others have obscure and subtle
problems of which you should be aware e.g. abs, strtok, map and more.
The Arduino absolute value function is a fairly simple function but
there is a trip-up in the way it is implemented on the Arduino system.
This is likely different to other C implementations.
Click to open Arduino absolute value page.
Click to open Arduino analogRead value page.
Find out the capabilities of the internal PWM generators in the Arduino:
The Arduino delay function takes an argument representing the number
of milliseconds to delay. Although it is used a lot, it is a blocking
function. When you get more complex projects you can not afford for the
processor to do nothing (as occurs with the delay function). The alternative is
the millis Arduino function.
Click to open Arduino delay page.
Here you can find out exactly how the function works with source code explanation and how to use macros to get faster operation.
Click to open Arduino digitalWrite page.
The for-loop is the main construct used to step through a series of values. It allows you to :
So you can set the start and exit conditions while updating a
variable up or down. In addition you can repeat a block of code while
the variable is updated.
Click to open Arduino for-loop page.
The Arduino conditional construct allows your code to make decisions
based on input variables. It gives you the standard if, then, else
decision making code that is common to all programming languages.
Find out how it is used in C/C++ in the link below.
Click to open Arduino if-else page.
The Arduino map function should be an obviously simple implementation
of mapping one range of values to another range of values but there is a
subtle problem that will not evenly distribute the ranges. Find out how to fix it in
the link.
Click to open Arduino map page.
The Arduino millis function, returns only the number of elapsed
milliseconds since reset of the board. Unlike delay, millis is a
non-blocking function. You can use it to time events while also allowing
the processor to do other tasks. You can also uses it in an equivalent,
but non-blocking way, to the delay function by calculating timing
delays.
There is a subtle 'feature' in the millis code that forces it to occasionally skip values - find out more in the link.
Click to open Arduino millis page.
Click to open Arduino pinMode page.
The functions are:
Click to open Arduino pulseIn page.
The function shiftIn is a serial to parallel converter that you can
use to get data from chips that send out data when driven by a clock
signal.
This is a software implementation of part of the SPI protocol and is consequently slower but can operate on any pin.
Click to open Arduino shiftIn page.
The function shiftOut is a parallel to serial converter that you can use
to send data to chips that accept data when driven by a clock signal.
This is a software implementaion of part of the SPI protocol and is consequently slower but can operate on any pin.
Click to open Arduino shiftOut page.
The switch-case construct allows you to minify your decision making
code if you use it in the right way. there is one pitfall that you
should avoid: described in the link below.
Click to open Arduino switch-case page.
Find out the difference between C strings and C++. You can observe
the differences with an example that shows how to decode a serial
command stream in both C and C++ string versions.
Also find out if there are any problems in either C strings or C++ strings [to do with memory usage - hint C++ uses the heap].
Click to open Arduino string page.
The Arduino strtok function is a function that steps through a string
rejecting some characters (the delimiters) while keeping other
characters (the tokens). At each call the function returns a pointer to
each set of tokens in turn.
Click to open Arduino strtok page.
The Arduino while-loop is another construct that lets you repeat
code. However in this case it is simpler that the for-loop. Since it
only has a condition for exit it allows you to write clearer code if it
can be used instead of a for-loop.
Unlike the for-loop you have to implemnent the variable increment
or decrement within the while loop block. Sometimes you need this for
the problem you are trying to solve.
The other form of the while-loop is the do-while-loop that always
executes some code before testing the exit condition. This can also be
useful in many use-cases.
Click to open Arduino while-loop page.
Comments
Have your say about what you just read! Leave me a comment in the box below.
Don’t see the comments box? Log in to your Facebook account, give Facebook consent, then return to this page and refresh it.