arduino的IIC.h库文件
时间: 2023-09-21 12:11:13 浏览: 163
以下是Arduino的Wire.h库文件的示例代码:
```c++
#ifndef TwoWire_h
#define TwoWire_h
#include <inttypes.h>
#define BUFFER_LENGTH 32
class TwoWire {
private:
static uint8_t rxBuffer[];
static uint8_t rxBufferIndex;
static uint8_t rxBufferLength;
static uint8_t txAddress;
static uint8_t txBuffer[];
static uint8_t txBufferIndex;
static uint8_t txBufferLength;
static uint8_t transmitting;
static void (*user_onRequest)(void);
static void (*user_onReceive)(int);
public:
TwoWire();
void begin();
void begin(uint8_t);
void begin(int);
void beginTransmission(uint8_t);
uint8_t endTransmission(void);
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(int, int);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *, size_t);
virtual int available(void);
virtual int read(void);
virtual int peek(void);
virtual void flush(void);
void onReceive( void (*)(int) );
void onRequest( void (*)(void) );
};
extern TwoWire Wire;
#endif
```
该库文件定义了TwoWire类,该类包含了许多I2C通讯所需的函数,例如beginTransmission(),requestFrom()和write()等函数。在使用I2C通讯时,您可以使用Wire对象调用这些函数。
阅读全文