24 #if defined(ARDUINO) && ARDUINO >= 100
45 #define i2cDelay() delayMicroseconds(5)
59 pinMode(_clockPin, OUTPUT);
60 pinMode(_dataPin, OUTPUT);
61 digitalWrite(_clockPin, HIGH);
62 digitalWrite(_dataPin, HIGH);
72 pinMode(_dataPin, OUTPUT);
75 digitalWrite(_dataPin, HIGH);
76 digitalWrite(_clockPin, HIGH);
79 digitalWrite(_dataPin, LOW);
81 digitalWrite(_clockPin, LOW);
89 pinMode(_dataPin, OUTPUT);
90 digitalWrite(_dataPin, LOW);
91 digitalWrite(_clockPin, HIGH);
93 digitalWrite(_dataPin, HIGH);
99 #define I2C_WRITE 0x00
100 #define I2C_WRITE10 0xF0
101 #define I2C_READ 0x01
102 #define I2C_READ10 0xF1
108 if (address < 0x80) {
110 write((uint8_t)((address << 1) | I2C_WRITE));
113 write((uint8_t)(((address >> 7) & 0x06)) | I2C_WRITE10);
114 write((uint8_t)address);
122 writeBit((value & mask) != 0);
139 if (address < 0x80) {
141 write((uint8_t)((address << 1) | I2C_READ));
144 write((uint8_t)(((address >> 7) & 0x06)) | I2C_READ10);
145 write((uint8_t)address);
163 for (uint8_t bit = 0; bit < 8; ++bit)
164 value = (value << 1) | readBit();
178 void SoftI2C::writeBit(
bool bit)
180 pinMode(_dataPin, OUTPUT);
182 digitalWrite(_dataPin, HIGH);
184 digitalWrite(_dataPin, LOW);
186 digitalWrite(_clockPin, HIGH);
188 digitalWrite(_clockPin, LOW);
192 bool SoftI2C::readBit()
194 pinMode(_dataPin, INPUT);
195 digitalWrite(_dataPin, HIGH);
196 digitalWrite(_clockPin, HIGH);
197 bool bit = digitalRead(_dataPin);
199 digitalWrite(_clockPin, LOW);
bool startRead(unsigned int address, unsigned int count)
Starts a read operation for count bytes by sending the start condition and the I2C control byte...
bool endWrite()
Ends the current write operation.
SoftI2C(uint8_t dataPin, uint8_t clockPin)
Constructs a new software I2C master on dataPin and clockPin.
unsigned int available()
Returns the number of bytes that are still available for reading.
uint8_t read()
Reads a single byte from the I2C bus.
void write(uint8_t value)
Writes a single byte value on the I2C bus.
unsigned int maxTransferSize() const
Returns the maximum number of bytes that can be read or written in a single request by this bus maste...
void startWrite(unsigned int address)
Starts a write operation by sending a start condition and the I2C control byte.