当前位置: 首页>>代码示例>>C++>>正文


C++ TwoWire::read方法代码示例

本文整理汇总了C++中TwoWire::read方法的典型用法代码示例。如果您正苦于以下问题:C++ TwoWire::read方法的具体用法?C++ TwoWire::read怎么用?C++ TwoWire::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TwoWire的用法示例。


在下文中一共展示了TwoWire::read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Read_Gyro

   // Read the ITG3200 Gyroscope
   void Read_Gyro() {
     // Point to the first data register
     I2C->beginTransmission(GyroAddress); 
     I2C->write(0x1B);  // point to the first data register
     I2C->endTransmission();
   
     // read 8 byte, from address 4 (Data Registers)
     I2C->beginTransmission(GyroAddress); 
     I2C->requestFrom(GyroAddress, 8);
     if (I2C->available() >= 8) {
       //Just confirming that the data order is Temp, X, Y, Z
       Gyro_T = (I2C->read() * 256) + I2C->read();  // Temp MSB * 256 + Temp LSB
       Gyro_X = (I2C->read() * 256) + I2C->read();  // X axis MSB * 256 + X axis LSB
       Gyro_Y = (I2C->read() * 256) + I2C->read();  // Y axis MSB * 256 + Y axis LSB
       Gyro_Z = (I2C->read() * 256) + I2C->read();  // Z axis MSB * 256 + Z axis LSB
       }
 
     // Incorrent number of returned bytes
     else {
       Serial.println("Recieving incorrect amount of bytes from Gyroscope");
       while(I2C->available()) {
         Serial.print("data byte = ");
         Serial.println(I2C->read(), DEC);    //print the returned number as a decimal
       }
     }
     I2C->endTransmission();
   }
开发者ID:sampsontech,项目名称:Teensyduino-Code,代码行数:28,代码来源:SparkFun_9DOF_4_Class.cpp

示例2: delay

unsigned int MCP342X::readADC()
{
    delay(80);
    unsigned int t;
  	Wire1.requestFrom(I2C_ADDRESS, (byte) 3);
	byte h = Wire1.read();
  	byte l = Wire1.read();
  	byte r = Wire1.read();
    t = (h << 8) |  l;
    return t;
}
开发者ID:KauzClay,项目名称:waggle,代码行数:11,代码来源:MCP342X.cpp

示例3:

static void read16(byte reg, uint16_t *value)
{
  Wire1.beginTransmission((uint8_t)BMP085_ADDRESS);
  #if ARDUINO >= 100
    Wire1.write((uint8_t)reg);
  #else
    Wire1.send(reg);
  #endif
  Wire1.endTransmission();
  Wire1.requestFrom((uint8_t)BMP085_ADDRESS, (byte)2);
  #if ARDUINO >= 100
    *value = (Wire1.read() << 8) | Wire1.read();
  #else
    *value = (Wire1.receive() << 8) | Wire1.receive();
  #endif
  Wire1.endTransmission();
}
开发者ID:KauzClay,项目名称:waggle,代码行数:17,代码来源:Adafruit_BMP085_U.cpp

示例4:

int PCF8574::i2cRead(uint8_t  value){
  Wire1.requestFrom((uint8_t )PCFaddress, (uint8_t )1);
  if (Wire1.available())  PCFPORTA = (int) Wire1.read();
  else PCFPORTA = (int)value; //error condition
  //return value;
   return PCFPORTA;

}
开发者ID:treehouselab,项目名称:flatBrain_Libraries,代码行数:8,代码来源:fB_PCF8574.cpp

示例5: millis

/** Read multiple bytes from an 8-bit device register.
 * @param useSPI  true : use SPI 
 * @param devAddr I2C slave device address
 * @param regAddr First register regAddr to read from
 * @param length Number of bytes to read
 * @param data Buffer to store read data in
 * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
 * @return Number of bytes read (0 indicates failure)
 */
int8_t I2Cdev::readBytes(bool useSPI, uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) {
    #ifdef I2CDEV_SERIAL_DEBUG
        Serial.print(useSPI ? "SPI (0x" : "I2C 0x");
        Serial.print(devAddr, HEX);
        Serial.print(") reading ");
        Serial.print(length, DEC);
        Serial.print(" bytes from 0x");
        Serial.print(regAddr, HEX);
        Serial.print("...");
    #endif
    int8_t count = 0;
	// I2C
	if (!useSPI) {
		Wire.beginTransmission(devAddr);
		#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
			Wire.send(regAddr);
		#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
			Wire.write(regAddr);
		#endif
		Wire.endTransmission();
		Wire.beginTransmission(devAddr);
		Wire.requestFrom(devAddr, length);

		uint32_t t1 = millis();
		for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) {
			#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
				data[count] = Wire.receive();
			#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
				data[count] = Wire.read();
			#endif
			#ifdef I2CDEV_SERIAL_DEBUG
				Serial.print(data[count], HEX);
				if (count + 1 < length) Serial.print(" ");
			#endif
		}
		if (timeout > 0 && millis() - t1 >= timeout && count < length) count = -1; // timeout
		Wire.endTransmission();
	} else {
	    digitalWrite(devAddr, LOW);
		byte Addr = regAddr | 0x80;
		SPI.transfer(Addr);
		for (uint8_t cnt=0; cnt < length; cnt++) {
			data[cnt] = SPI.transfer(0);
			count++;
		}
		digitalWrite(devAddr, HIGH);
	}
    #ifdef I2CDEV_SERIAL_DEBUG
        Serial.print(". Done (");
        Serial.print(count, DEC);
        Serial.println(" read).");
    #endif
    return count;
}
开发者ID:1018365842,项目名称:FreeIMU-Updates,代码行数:63,代码来源:I2Cdev.cpp

示例6: Read_Accel

    // Read the ADXL345 Accelerometer
    void Read_Accel() {
      I2C->beginTransmission(AccelAddress);  // start transmission to device 
      I2C->write(0x32);                       // point to the first data register DATAX0
      I2C->endTransmission();                // end transmission

      // read 6 byte, from address 32 (Data Registers)
      I2C->beginTransmission(AccelAddress);  // start transmission to device 
      I2C->requestFrom(AccelAddress, 6);
      if (I2C->available() >= 6) {
        Accel_X = I2C->read() + (I2C->read() * 256);  // X axis LSB + X axis MSB * 256
        Accel_Y = I2C->read() + (I2C->read() * 256);  // Y axis LSB + Y axis MSB * 256
        Accel_Z = I2C->read() + (I2C->read() * 256);  // Z axis LSB + Z axis MSB * 256
      }

      // Incorrent number of returned bytes
      else {
        Serial.println("Recieving incorrect amount of bytes from Accelerometer");
        while(I2C->available()) {
          Serial.print("data byte = ");
          Serial.println(I2C->read(), DEC);    //print the returned number as a decimal
        }
      }
      I2C->endTransmission();
    }
开发者ID:sampsontech,项目名称:Teensyduino-Code,代码行数:25,代码来源:SparkFun_9DOF_4_Class.cpp

示例7: millis

/** Read multiple bytes from an 8-bit device register.
 * @param devAddr I2C slave device address
 * @param regAddr First register regAddr to read from
 * @param length Number of bytes to read
 * @param data Buffer to store read data in
 * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
 * @return Number of bytes read (0 indicates failure)
 */
int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) {
    #ifdef I2CDEV_SERIAL_DEBUG
        Serial.print("I2C (0x");
        Serial.print(devAddr, HEX);
        Serial.print(") reading ");
        Serial.print(length, DEC);
        Serial.print(" bytes from 0x");
        Serial.print(regAddr, HEX);
        Serial.print("...");
    #endif

    int8_t count = 0;

    Wire.beginTransmission(devAddr);
    #if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
        Wire.send(regAddr);
    #elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
        Wire.write(regAddr);
    #endif
    Wire.endTransmission();

    Wire.beginTransmission(devAddr);
    Wire.requestFrom(devAddr, length);

    uint32_t t1 = millis();
    for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) {
        #if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
            data[count] = Wire.receive();
        #elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
            data[count] = Wire.read();
        #endif
        #ifdef I2CDEV_SERIAL_DEBUG
            Serial.print(data[count], HEX);
            if (count + 1 < length) Serial.print(" ");
        #endif
    }
    if (timeout > 0 && millis() - t1 >= timeout && count < length) count = -1; // timeout

    Wire.endTransmission();

    #ifdef I2CDEV_SERIAL_DEBUG
        Serial.print(". Done (");
        Serial.print(count, DEC);
        Serial.println(" read).");
    #endif

    return count;
}
开发者ID:zul00,项目名称:imu-st32f1,代码行数:56,代码来源:I2Cdev.cpp

示例8: Read_Compass

    // Read the HMC5883L Compass
    void Read_Compass()  {
      // Point to the first data register
      I2C->beginTransmission(CompassAddress); 
      I2C->write(0x03);  // point to the first data register
      I2C->endTransmission();
    
      // read 6 byte, from address 3 (Data Registers)
      I2C->beginTransmission(CompassAddress); 
      I2C->requestFrom(CompassAddress, 6);
      if (I2C->available() >= 6) {
        //Just confirming that the data register order is X Z Y (ie NOT X Y Z) 
        Compass_Raw_X = (I2C->read() * 256) + I2C->read();  // X axis MSB * 256 + X axis LSB
        Compass_Raw_Z = (I2C->read() * 256) + I2C->read();  // Z axis MSB * 256 + Z axis LSB
        Compass_Raw_Y = (I2C->read() * 256) + I2C->read();  // Y axis MSB * 256 + Y axis LSB
      }

  
      // Incorrent number of returned bytes
      else {
        Serial.println("Recieving incorrect amount of bytes from Compass");
        while(I2C->available()) {
          Serial.print("data byte = ");
          Serial.println(I2C->read(), DEC);    //print the returned number as a decimal
        }
      }
      I2C->endTransmission();
  
      // Scale the Raw readings based on the sensor scale (Gauss = 1.3 & Scale = 0.92)
      Compass_Raw_X *= 0.92;
      Compass_Raw_Y *= 0.92;
      Compass_Raw_Z *= 0.92;
    
      // Update the Max Min limit readings
      if (Compass_Raw_X > Compass_Max_X) Compass_Max_X = Compass_Raw_X;
      if (Compass_Raw_X < Compass_Min_X) Compass_Min_X = Compass_Raw_X;
      if (Compass_Raw_Y > Compass_Max_Y) Compass_Max_Y = Compass_Raw_Y;
      if (Compass_Raw_Y < Compass_Min_Y) Compass_Min_Y = Compass_Raw_Y;
      if (Compass_Raw_Z > Compass_Max_Z) Compass_Max_Z = Compass_Raw_Z;
      if (Compass_Raw_Z < Compass_Min_Z) Compass_Min_Z = Compass_Raw_Z;
  
      // Update the offset
      Compass_Offset_X = (Compass_Max_X + Compass_Min_X) / 2;
      Compass_Offset_Y = (Compass_Max_Y + Compass_Min_Y) / 2;
      Compass_Offset_Z = (Compass_Max_Z + Compass_Min_Z) / 2;
  
      // Calculate calibrated readings
      Compass_Calib_X = Compass_Raw_X - Compass_Offset_X;
      Compass_Calib_Y = Compass_Raw_Y - Compass_Offset_Y;
      Compass_Calib_Z = Compass_Raw_Z - Compass_Offset_Z;
  
      //--- Calculate the X Y plane heading ---
      // Calculate heading (radians) using the X, Y plane - Assuming magnetometer is level
      Compass_Heading = atan2(Compass_Calib_Y, Compass_Calib_X);
      // Adjust with Declination error (magnetic north vs true north)
      Compass_Heading += Compass_Declination_Angle;
      // Correct for when signs are reversed.
      if(Compass_Heading < 0) Compass_Heading += 2*PI;
      // Check for wrap due to addition of declination.
      if(Compass_Heading > 2*PI) Compass_Heading -= 2*PI;  
      // Convert radians to degrees for readability.
      Compass_Heading *= 180/M_PI;
  
      //--- Calculate the X Z plane heading ---
      // Calculate heading (radians) using the X, Z plane
      Compass_Heading_XZ = atan2(Compass_Calib_Z, Compass_Calib_X);
      // Adjust with Declination error (magnetic north vs true north)
      Compass_Heading_XZ += Compass_Declination_Angle;
      // Correct for when signs are reversed.
      if(Compass_Heading_XZ < 0) Compass_Heading_XZ += 2*PI;
      // Check for wrap due to addition of declination.
      if(Compass_Heading_XZ > 2*PI) Compass_Heading_XZ -= 2*PI;  
      // Convert radians to degrees for readability.
      Compass_Heading_XZ *= 180/M_PI;
  
      //--- Calculate the Y Z plane heading ---
      // Calculate heading (radians) using the Y, Z plane
      Compass_Heading_YZ = atan2(Compass_Calib_Z, Compass_Calib_Y);
      // Adjust with Declination error (magnetic north vs true north)
      Compass_Heading_YZ += Compass_Declination_Angle;
      // Correct for when signs are reversed.
      if(Compass_Heading_YZ < 0) Compass_Heading_YZ += 2*PI;
      // Check for wrap due to addition of declination.
      if(Compass_Heading_YZ > 2*PI) Compass_Heading_YZ -= 2*PI;  
      // Convert radians to degrees for readability.
      Compass_Heading_YZ *= 180/M_PI;
    }
开发者ID:sampsontech,项目名称:Teensyduino-Code,代码行数:87,代码来源:SparkFun_9DOF_4_Class.cpp

示例9: NunchuckReadData

static bool NunchuckReadData(TwoWire& interface, NunchuckData& data)
{
  interface.requestFrom(0x52, 6);

  data.jX =   interface.read();
  data.jY =   interface.read();
  data.accX = interface.read();
  data.accY = interface.read();
  data.accZ = interface.read();
  data.buttons = interface.read();

  data.accZ<<=2;
  data.accZ|=data.buttons>>6;

  data.accY<<=2;
  data.accY|=(data.buttons>>4)&0x3;

  data.accX<<=2;
  data.accX|=(data.buttons>>2)&0x3;

  data.buttons&=0x3;

  SERIAL_PORT_MONITOR.print("Joy : ");
  SERIAL_PORT_MONITOR.print(data.jX);
  SERIAL_PORT_MONITOR.print(", ");
  SERIAL_PORT_MONITOR.print(data.jY);

  SERIAL_PORT_MONITOR.print("\tAcc : ");
  SERIAL_PORT_MONITOR.print(data.accX);
  SERIAL_PORT_MONITOR.print(", ");
  SERIAL_PORT_MONITOR.print(data.accY);
  SERIAL_PORT_MONITOR.print(", ");
  SERIAL_PORT_MONITOR.print(data.accZ);

  SERIAL_PORT_MONITOR.print("\tBtn : ");
  SERIAL_PORT_MONITOR.print(" [");
  SERIAL_PORT_MONITOR.print(data.buttons);
  SERIAL_PORT_MONITOR.print("] ");

  switch(data.buttons)
  {
    case 0x0ul:
      SERIAL_PORT_MONITOR.println("C + Z");
      break;

    case 0x1ul:
      SERIAL_PORT_MONITOR.println("C");
      break;

    case 0x2ul:
      SERIAL_PORT_MONITOR.println("Z");
      break;

    case 0x3ul:
      SERIAL_PORT_MONITOR.println("No key");
      break;

    default:
      break;
  }

  interface.beginTransmission(0x52);// transmit to device 0x52
  interface.write((uint8_t)0x00);// sends a zero.
  interface.endTransmission();// stop transmitting

  return 1;
}
开发者ID:aethaniel,项目名称:ExperimentalCore-sam,代码行数:67,代码来源:wire_wii_nunchuck.cpp


注:本文中的TwoWire::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。