Hardware Reference
In-Depth Information
The location of the preferences.txt file is listed in the Preferences dialog box. It is good to know this because
you may need to edit this file.
Changes to Sketches
Whenever you write an Arduino sketch, you are using the core functions and collection of objects that are always
accessible, without needing to include external libraries in your sketch. For instance, Serial can be used without
having to declare it. The Arduino IDE preprocesses the Arduino sketch before compiling. This process includes the
Arduino.h file from core. Some of the files from core have to be included manually, as the Ethernet core does.
The Ethernet core features are needed for the Arduino Ethernet board, but because not all Arduino boards have
Ethernet, the files are available but not automatically included.
Arduino achieves its simplicity by preprocessing the sketch and automatically generating a basic functional set.
So, you never have to worry about including Arduino.h and creating header files for sketches, unless you create your
own Arduino libraries. Arduino libraries have to be written in standard C/C++; I will cover their creation later,
in Chapter 14.
Here, you will examine how the default core functionality has changed. Then the chapter will cover how these
changes have affected the default libraries that come with Arduino.
These default libraries have been replaced by new variants with new features. Also, WProgram.h has been change
to Arduino.h .
API Updates
This section will discuss the changes to the API.
pinMode
pinMode has been updated to support INPUT_PULLUP . This adds clean support for creating buttons and switches that
are active high by default, and when activated pulled low. Listing 1-1 shows an example.
Listing 1-1. pinMode INPUT_PULLUP Resistor Feature
setup()
{
Serial.begin(9600);
pinMode(10, INPUT);
digitalWrite(10, HIGH);
int val = digitalRead(10);
Serial.print(val);
}
In Arduino 1.0.x you can do it this way:
setup()
{
Serial.begin(9600);
pinMode(10, INPUT_PULLUP);
int val = digitalRead(10);
Serial.print(val);
}
 
Search WWH ::




Custom Search