Hardware Reference
In-Depth Information
If there are no examples available, then all is not lost. With the open source
nature of Arduino, most libraries are also open source, so you can read the
contents of the library. These i les are written in C++ but are easily readable
and can be opened with any text editor. Opening the SI1145 library header (the
.h i le) shows the following lines in the source code:
class Adafruit_SI1145 {
public:
Adafruit_SI1145(void);
boolean begin();
void reset();
uint16_t readUV();
uint16_t readIR();
uint16_t readVisible();
uint16_t readProx();
private:
uint16_t read16(uint8_t addr);
uint8_t read8(uint8_t addr);
void write8(uint8_t reg, uint8_t val);
uint8_t readParam(uint8_t p);
uint8_t writeParam(uint8_t p, uint8_t v);
uint8_t _addr;
};
The class name is a reference to a C++ class . This becomes an object in your
sketch. This object contains both variables and functions. It consists of several
parts. The private section includes functions and variables that will be
visible only inside the class. The sketch cannot see them and cannot modify the
variables, or call these functions. What the sketch can see are the members of
the public part. As you can see, the previous function is found here, readUV() ,
but there are others: readIR(), readVisible(), and readProx() . Although the
function of readVisible() seems obvious, readProx() isn't clear and wasn't
used in the example sketch. Header i les rarely have comments, so you may
not know immediately what this function does. This is a declaration; it tells the
compiler that somewhere in the .cpp i le there is a function called readProx() ,
so that is where you need to look for the answer.
This is the i rst few lines of the function found in the C++ i le:
// returns "Proximity" - assumes an IR LED is attached to LED
uint16_t Adafruit_SI1145::readProx(void)
{
return read16(0x26);
}
Just a few lines of comments, and you can tell what the function does. So this
function calculates the Heat index, the human-felt equivalence temperature—an
interesting addition that could be useful for weather stations.
Search WWH ::




Custom Search