Hardware Reference
In-Depth Information
8 bits of data at a time, the entire output of the chip. To achieve this, two more
variables will be needed; _chip0Output and _chip1Output will both contain
8-bits of data, the data that will be sent to the chip. The user does not need to
worry about how a bit of data is sent, or even be aware that the library cannot
send a single bit, which is one of the reasons why libraries are so powerful.
The library takes care of the details, letting the user concentrate on the sketch.
Finally, a begin() function will be written. This function will initialize the
chip to a power-on state and will be called when the user is ready.
By simply thinking about what the user would need the shield to do, you'll
have a good idea of what the header i le should contain. It will look something
like this (i lename: PCF8574AP.h ):
#include "Arduino.h"
class PCF8574AP
{
private:
int _chip0Address;
int _chip1Address;
int_chip0Output;
int _chip1Output;
public:
PCF8574AP(int chip1, int chip2);
void begin();
bool writeBit(bool bit, int pos);
bool writeByte(int data, bool chipSelect);
bool writeWord(int data);
bool readBit(int pos);
int readByte(bool chipSelect);
int readWord();
};
Now that the structure is created, it is time to work on the C++ i le, called
PCF8754AP.cpp . First, add references to the libraries it depends on— Arduino.h
and Wire.h —as well as the library header, followed by the constructor:
#include "Arduino.h"
#include "Wire.h"
#include "PCF8574AP.h"
PCF8574AP::PCF8574AP(uint8_t chip0, uint8_t chip1)
{
_chip0Address = chip0;
_chip1Address = chip1;
}
Search WWH ::




Custom Search