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


Java I2CDevice.write方法代码示例

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


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

示例1: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public static void main(String[] args) 
        throws IOException, I2CFactory.UnsupportedBusNumberException, 
        InterruptedException {
    
    // Connect to I2C bus 1
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);
    
    // Create device object
    I2CDevice device = i2c.getDevice(PCF8574P_ADDRESS);
    
    while(true) {
        device.write((byte)0x40,(byte)0);
        Thread.sleep(1000);
        device.write((byte)0x40,(byte)1);
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:17,代码来源:PFC8574P.java

示例2: I2CWrite

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public byte I2CWrite(int busAddress, int deviceAddress, byte value) {
	I2CDevice device = getDevice(busAddress, deviceAddress);

	if (device == null) {
		error("bus %d device %d not valid", busAddress, deviceAddress);
		return -1;
	}

	try {
		device.write(value);
		return value;
	} catch (Exception e) {
		Logging.logError(e);
	}
	return -1;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:17,代码来源:RasPi.java

示例3: writeToDisplay

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public void writeToDisplay(int address, byte b0, byte b1, byte b2, byte b3) {
  try {

    I2CBus i2cbus = I2CFactory.getInstance(rasPiBus);
    I2CDevice device = i2cbus.getDevice(address);
    device.write(address, (byte) 0x80);

    I2CDevice display = i2cbus.getDevice(0x38);
    display.write(new byte[] { 0, 0x17, b0, b1, b2, b3 }, 0, 6);

    device.write(address, (byte) 0x83);

  } catch (Exception e) {
    Logging.logError(e);
  }
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:17,代码来源:PickToLight.java

示例4: processCommand

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public static boolean processCommand(I2CDevice device, byte[] command) throws IOException {
	if (Objects.nonNull(device)) {
		device.write(command);
		return true;
	} else {
		throw new TankSystemException("device not available for command");
	}

}
 
开发者ID:Robo4J,项目名称:robo4j-rpi-ard-tank-example,代码行数:10,代码来源:TankUtil.java

示例5: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Alter these values to change device operation
 *
 * @param args
 * @throws java.io.IOException
 * @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
 * @throws java.lang.InterruptedException
 */
// Device addresses 0x29, 0x39, 0x49 are possible by setting addr pin to
// GND, Floating, and +3.3V respectively
public static void main(String[] args)
        throws IOException, I2CFactory.UnsupportedBusNumberException, InterruptedException {
    // Set up the I2C libraries
    I2CBus I2C_BUS;
    I2CDevice TSL2561;

    // Get i2c I2C_BUS
    // Number depends on RasPI version
    I2C_BUS = I2CFactory.getInstance(I2CBus.BUS_1);

    System.out.println("Connected to bus. OK.");

    // Get device itself
    TSL2561 = I2C_BUS.getDevice(TSL2561_ADDR);
    System.out.println("Connected to device.");

    System.out.println("Device ID: " + TSL2561.read(TSL2561_REG_ID));

    // Initialize device by issuing command with data value 0x03        
    TSL2561.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    while (true) {
        System.out.println("Waiting...");
        Thread.sleep(500);

        byte d0L = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_0_LOW));
        byte d0H = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_0_HIGH));
        byte d1L = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_1_LOW));
        byte d1H = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_1_HIGH));

        if (VERBOSE) {
            System.out.println("Data 0: " + bytesToInt(d0H, d0L));
            System.out.println("Data 1: " + bytesToInt(d1H, d1L));
        }
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:47,代码来源:TSL2561_First_Test.java

示例6: writeToDisplay

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public void writeToDisplay(int address, byte b0, byte b1, byte b2, byte b3) {
	try {

		I2CBus i2cbus = I2CFactory.getInstance(rasPiBus);
		I2CDevice device = i2cbus.getDevice(address);
		device.write(address, (byte) 0x80);

		I2CDevice display = i2cbus.getDevice(0x38);
		display.write(new byte[] { 0, 0x17, b0, b1, b2, b3 }, 0, 6);

		device.write(address, (byte) 0x83);

	} catch (Exception e) {
		Logging.logError(e);
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:17,代码来源:PickToLight.java

示例7: writeRaw

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public void writeRaw(int busAddress, int deviceAddress, byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7, byte d8, byte d9, byte d10, byte d11, byte d12,
		byte d13, byte d14, byte d15) {
	try {
		log.info("--------writeRaw begin -------------");

		log.info(String.format("test %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15));
		I2CDevice device = getDevice(busAddress, deviceAddress);
		device.write(0x00, new byte[] { d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15 }, 0, 16);

		log.info("--------writeRaw end-------------");
	} catch (Exception e) {
		Logging.logError(e);
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:15,代码来源:RasPi.java

示例8: writeDisplay

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public byte[] writeDisplay(byte[] data) {
	if (device == null) {
		log.error("device is null");
		return data;
	}

	try {

		if (log.isDebugEnabled()) {
			logByteArray("writeDisplay", data);
		}

		// select display
		device.write((byte) (selector &= ~MASK_DISPLAY)); // FIXME NOT
															// CORRECT !

		I2CDevice display = i2cbus.getDevice(0x38);
		display.write(data, 0, data.length);

		// de-select display
		device.write((byte) (selector |= MASK_DISPLAY));// FIXME NOT CORRECT
														// ! for LED

	} catch (Exception e) {
		log.error(String.format("writeDisplay device %d error in writing", address.controller));
		Logging.logError(e);
	}

	return data;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:31,代码来源:Module.java

示例9: set_leds

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Write the given intensity value to all LEDs
 * @param device - the PiGlow I2C device
 * @param intensity - the LED intensity value to set
 * @throws IOException
 */
static void set_leds(I2CDevice device, byte intensity) throws IOException {
   byte[] values = new byte[LED_COUNT];
   Arrays.fill(values, intensity);
   device.write(CMD_SET_PWM_VALUES, values, 0, values.length);
   device.write(CMD_UPDATE, ff);
}
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:13,代码来源:PiGlowTests.java

示例10: set_arm

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Sets the leds of the given arm to the given intensity.
 * @param device - the PiGlow I2C device
 * @param arm - the arm used to index into the
 * @param intensity - the LED intensity value to set
 * @throws IOException
 */
static void set_arm(I2CDevice device, int arm, byte intensity) throws IOException {
   byte[] values = new byte[LED_COUNT];
   Arrays.fill(values, (byte)0);
   for(int n = 0; n < ARMS[arm].length; n ++)
      values[ARMS[arm][n]] = intensity;
   device.write(CMD_SET_PWM_VALUES, values, 0, values.length);
   device.write(CMD_UPDATE, ff);
}
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:16,代码来源:PiGlowTests.java

示例11: set_led

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 *
 * @param device
 * @param led
 * @param intensity
 * @throws IOException
 */
static void set_led(I2CDevice device, int led, byte intensity) throws IOException {
   byte[] values = new byte[LED_COUNT];
   Arrays.fill(values, (byte)0);
   values[led] = intensity;
   device.write(CMD_SET_PWM_VALUES, values, 0, values.length);
   device.write(CMD_UPDATE, ff);
}
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:15,代码来源:PiGlowTests.java

示例12: writeDisplay

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
public byte[] writeDisplay(byte[] data) {
  if (device == null) {
    log.error("device is null");
    return data;
  }

  try {

    if (log.isDebugEnabled()) {
      logByteArray("writeDisplay", data);
    }

    // select display
    device.write((byte) (selector &= ~MASK_DISPLAY)); // FIXME NOT
    // CORRECT !

    I2CDevice display = i2cbus.getDevice(0x38);
    display.write(data, 0, data.length);

    // de-select display
    device.write((byte) (selector |= MASK_DISPLAY));// FIXME NOT CORRECT
    // ! for LED

  } catch (Exception e) {
    log.error(String.format("writeDisplay device %d error in writing", address.controller));
    Logging.logError(e);
  }

  return data;
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:31,代码来源:Module.java

示例13: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the OrangePi platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.ORANGEPI);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_0);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:64,代码来源:I2CExample.java

示例14: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the Odroid platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.ODROID);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    // - I2CBus.BUS_1 uses 40 pin header, pin #3 as I2CA_SDA (SDA1) and pin #5 as I2CA_SCL (SCL1)
    // - I2CBus.BUS_2 uses 40 pin header, pin #27 as I2CB_SDA (SDA2) and pin #28 as I2CB_SCL (SCL2)
    // see GPIO PIN MAP here: http://www.hardkernel.com/main/products/prdt_info.php?g_code=G143703355573&tab_idx=2
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_2);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:67,代码来源:I2CExample.java

示例15: main

import com.pi4j.io.i2c.I2CDevice; //导入方法依赖的package包/类
/**
 * Program Main Entry Point
 *
 * @param args
 * @throws InterruptedException
 * @throws PlatformAlreadyAssignedException
 * @throws IOException
 * @throws UnsupportedBusNumberException
 */
public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {

    // ####################################################################
    //
    // since we are not using the default Raspberry Pi platform, we should
    // explicitly assign the platform as the BananaPro platform.
    //
    // ####################################################################
    PlatformManager.setPlatform(Platform.BANANAPRO);

    // create Pi4J console wrapper/helper
    // (This is a utility class to abstract some of the boilerplate code)
    final Console console = new Console();

    // print program title/header
    console.title("<-- The Pi4J Project -->", "I2C Example");

    // allow for user to exit program using CTRL-C
    console.promptForExit();

    // get the I2C bus to communicate on
    // - I2CBus.BUS_2 uses header pin CON6:3 as SDA and header pin CON6:5 as SCL
    // - I2CBus.BUS_3 uses header pin CON6:27 as SDA and header pin CON6:28 as SCL
    I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_2);

    // create an I2C device for an individual device on the bus that you want to communicate with
    // in this example we will use the default address for the TSL2561 chip which is 0x39.
    I2CDevice device = i2c.getDevice(TSL2561_ADDR);

    // next, lets perform am I2C READ operation to the TSL2561 chip
    // we will read the 'ID' register from the chip to get its part number and silicon revision number
    console.println("... reading ID register from TSL2561");
    int response = device.read(TSL2561_REG_ID);
    console.println("TSL2561 ID = " + String.format("0x%02x", response) + " (should be 0x50)");

    // next we want to start taking light measurements, so we need to power up the sensor
    console.println("... powering up TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

    // wait while the chip collects data
    Thread.sleep(500);

    // now we will perform our first I2C READ operation to retrieve raw integration
    // results from DATA_0 and DATA_1 registers
    console.println("... reading DATA registers from TSL2561");
    int data0 = device.read(TSL2561_REG_DATA_0);
    int data1 = device.read(TSL2561_REG_DATA_1);

    // print raw integration results from DATA_0 and DATA_1 registers
    console.println("TSL2561 DATA 0 = " + String.format("0x%02x", data0));
    console.println("TSL2561 DATA 1 = " + String.format("0x%02x", data1));

    // before we exit, lets not forget to power down light sensor
    console.println("... powering down TSL2561");
    device.write(TSL2561_REG_CONTROL, TSL2561_POWER_DOWN);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:66,代码来源:I2CExample.java


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