|
这堆报错都怎么改啊?
In file included from L3G4200D.cpp:1:
L3G4200D.h:89: error: 'byte' has not been declared
L3G4200D.h:89: error: 'byte' has not been declared
L3G4200D.h:91: error: 'byte' does not name a type
L3G4200D.cpp:22: error: variable or field 'writeReg' declared void
L3G4200D.cpp:22: error: 'byte' was not declared in this scope
L3G4200D.cpp:22: error: 'byte' was not declared in this scope
L3G4200D.cpp:31: error: 'byte' does not name a type
L3G4200D.cpp: In member function 'void L3G4200D::read()':
L3G4200D.cpp:48: error: 'Wire' was not declared in this scope
L3G4200D.cpp:57: error: 'uint8_t' was not declared in this scope
L3G4200D.cpp:57: error: expected `;' before 'xla'
L3G4200D.cpp:58: error: expected `;' before 'xha'
L3G4200D.cpp:59: error: expected `;' before 'yla'
L3G4200D.cpp:60: error: expected `;' before 'yha'
L3G4200D.cpp:61: error: expected `;' before 'zla'
L3G4200D.cpp:62: error: expected `;' before 'zha'
L3G4200D.cpp:64: error: 'xha' was not declared in this scope
L3G4200D.cpp:64: error: 'xla' was not declared in this scope
L3G4200D.cpp:65: error: 'yha' was not declared in this scope
L3G4200D.cpp:65: error: 'yla' was not declared in this scope
L3G4200D.cpp:66: error: 'zha' was not declared in this scope
L3G4200D.cpp:66: error: 'zla' was not declared in this scope
源程序(L3G4200.h)
#ifndef L3G4200D_h
#define L3G4200D_h
#include <WProgram.h> // for byte data type
// register addresses
#define L3G4200D_WHO_AM_I 0x0F
#define L3G4200D_CTRL_REG1 0x20
#define L3G4200D_CTRL_REG2 0x21
#define L3G4200D_CTRL_REG3 0x22
#define L3G4200D_CTRL_REG4 0x23
#define L3G4200D_CTRL_REG5 0x24
#define L3G4200D_REFERENCE 0x25
#define L3G4200D_OUT_TEMP 0x26
#define L3G4200D_STATUS_REG 0x27
#define L3G4200D_OUT_X_L 0x28
#define L3G4200D_OUT_X_H 0x29
#define L3G4200D_OUT_Y_L 0x2A
#define L3G4200D_OUT_Y_H 0x2B
#define L3G4200D_OUT_Z_L 0x2C
#define L3G4200D_OUT_Z_H 0x2D
#define L3G4200D_FIFO_CTRL_REG 0x2E
#define L3G4200D_FIFO_SRC_REG 0x2F
#define L3G4200D_INT1_CFG 0x30
#define L3G4200D_INT1_SRC 0x31
#define L3G4200D_INT1_THS_XH 0x32
#define L3G4200D_INT1_THS_XL 0x33
#define L3G4200D_INT1_THS_YH 0x34
#define L3G4200D_INT1_THS_YL 0x35
#define L3G4200D_INT1_THS_ZH 0x36
#define L3G4200D_INT1_THS_ZL 0x37
#define L3G4200D_INT1_DURATION 0x38
class L3G4200D
{
public:typedef struct vector
{
float x, y, z;
}
vector;
vector g; // gyro angular velocity readings
void enableDefault(void);
void writeReg(byte reg, byte value);
byte readReg(byte reg);
void read(void);
// vector functions
static void vector_cross(const vector *a, const vector *b, vector *out);
static float vector_dot(const vector *a,const vector *b);
static void vector_normalize(vector *a);
};
#endif
源程序(L3G4200.cpp)
#include <L3G4200D.h>
#include <Wire.h>
#include <math.h>
// Defines ////////////////////////////////////////////////////////////////
// The Arduino two-wire interface uses a 7-bit number for the address,
// and sets the last bit correctly based on reads and writes
#define GYR_ADDRESS (0xD2 >> 1)
// Public Methods //////////////////////////////////////////////////////////////
// Turns on the L3G4200D's gyro and places it in normal mode.
void L3G4200D::enableDefault(void)
{
// 0x0F = 0b00001111
// Normal power mode, all axes enabled
writeReg(L3G4200D_CTRL_REG1, 0x0F);
}
// Writes a gyro register
void L3G4200D::writeReg(byte reg, byte value)
{
Wire.beginTransmission(GYR_ADDRESS);
Wire.send(reg);
Wire.send(value);
Wire.endTransmission();
}
// Reads a gyro register
byte L3G4200D::readReg(byte reg)
{
byte value;
Wire.beginTransmission(GYR_ADDRESS);
Wire.send(reg);
Wire.endTransmission();
Wire.requestFrom(GYR_ADDRESS, 1);
value = Wire.receive();
Wire.endTransmission();
return value;
}
// Reads the 3 gyro channels and stores them in vector g
void L3G4200D::read()
{
Wire.beginTransmission(GYR_ADDRESS);
// assert the MSB of the address to get the gyro
// to do slave-transmit subaddress updating.
Wire.send(L3G4200D_OUT_X_L | (1 << 7));
Wire.endTransmission();
Wire.requestFrom(GYR_ADDRESS, 6);
while (Wire.available() < 6);
uint8_t xla = Wire.receive();
uint8_t xha = Wire.receive();
uint8_t yla = Wire.receive();
uint8_t yha = Wire.receive();
uint8_t zla = Wire.receive();
uint8_t zha = Wire.receive();
g.x = xha << 8 | xla;
g.y = yha << 8 | yla;
g.z = zha << 8 | zla;
}
void L3G4200D::vector_cross(const vector *a,const vector *b, vector *out)
{
out->x = a->y*b->z - a->z*b->y;
out->y = a->z*b->x - a->x*b->z;
out->z = a->x*b->y - a->y*b->x;
}
float L3G4200D::vector_dot(const vector *a,const vector *b)
{
return a->x*b->x+a->y*b->y+a->z*b->z;
}
void L3G4200D::vector_normalize(vector *a)
{
float mag = sqrt(vector_dot(a,a));
a->x /= mag;
a->y /= mag;
a->z /= mag;
}
|
|