本文整理汇总了Java中com.pi4j.io.i2c.I2CBus类的典型用法代码示例。如果您正苦于以下问题:Java I2CBus类的具体用法?Java I2CBus怎么用?Java I2CBus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
I2CBus类属于com.pi4j.io.i2c包,在下文中一共展示了I2CBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
@Override
public void initialize(ConfigurationProvider configurationProvider) throws IOException {
// this is a "robot leg problem"
// see https://github.com/google/guice/wiki/FrequentlyAskedQuestions#How_do_I_build_two_similar_but_slightly_different_trees_of_objec
// we have a leftMotor and a rightMotor - same class, different configuration
// I did not use the private module solution as it is a bit scary to look at. But maybe:
// TODO: clean this mess up - MotorControllers should be injected
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
I2CDevice device = bus.getDevice(0x40);
PCA9685PWMGenerator driver = new PCA9685PWMGenerator(device);
driver.open();
driver.setFrequency(50);
leftMotor = new MotorControllerImpl(driver.getOutput(14),
configurationProvider.bind("motorLeft", MotorControllerConfiguration.class));
rightMotor = new MotorControllerImpl(driver.getOutput(15),
configurationProvider.bind("motorRight", MotorControllerConfiguration.class));
LOGGER.debug("Completed setting up DriveController");
}
示例2: main
import com.pi4j.io.i2c.I2CBus; //导入依赖的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);
}
}
示例3: PumpDiagGuiSingle
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
/**
* Creates new form MainWindow
*
* @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
* @throws java.io.IOException
*/
public PumpDiagGuiSingle() throws I2CFactory.UnsupportedBusNumberException, IOException, IOException, InterruptedException {
gpio = GpioFactory.getInstance(); // Singleton instance
mcpProvider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x23);
// Provision direction control pins as outputs
System.out.println("Provisioning direction pin");
dir = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A7, "Direction", PinState.LOW);
// Provision step control pins as outputs
System.out.println("Provisioning step pin");
step = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A6, "Step", PinState.LOW);
// Provision enable pins as outputs.
// Note that the pin state "high" means the pump is disabled;
// the enable pump on the chip is inverted.
System.out.println("Provisioning enable pin");
enable = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A5, "~Enable", PinState.HIGH);
}
示例4: RgbSensor
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public RgbSensor()
throws IOException, I2CFactory.UnsupportedBusNumberException {
// Get the I2C Bus
this.i2cBus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get device
this.device = i2cBus.getDevice(ADDR_DEFAULT);
// Initialize device
this.readU8(0x44);
// Enable device
this.write8(TCS34725_ENABLE, (byte) TCS34725_ENABLE_PON);
waitfor(10);
this.write8(TCS34725_ENABLE, (byte) (TCS34725_ENABLE_PON | TCS34725_ENABLE_AEN));
}
示例5: initialize
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
@Override
public void initialize(ConfigurationProvider configurationProvider) throws IOException {
super.initialize(configurationProvider);
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
I2CDevice device = bus.getDevice(0x40);
PCA9685PWMGenerator driver = new PCA9685PWMGenerator(device);
driver.open();
driver.setFrequency(50);
horizontalHeadMotor = new ServoControllerImpl(driver.getOutput(1),
configurationProvider.bind("servo1", ServoConfiguration.class));
verticalHeadMotor = new ServoControllerImpl(driver.getOutput(0),
configurationProvider.bind("servo0", ServoConfiguration.class));
horizontalHeadMotor.setPosition(headPositionHorizontal);
verticalHeadMotor.setPosition(headPositionVertical);
LOGGER.debug("Completed setting up HeadController");
}
示例6: main
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP4725 DAC Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create gpio provider
final MCP4725GpioProvider gpioProvider = new MCP4725GpioProvider(I2CBus.BUS_1, MCP4725GpioProvider.MCP4725_ADDRESS_1);
// create output pin
final GpioPinAnalogOutput vout = gpio.provisionAnalogOutputPin(gpioProvider, MCP4725Pin.OUTPUT);
// generate sinus wave on output pin
for (int i = 0; i < 360; i++) {
double y = Math.sin(Math.toRadians(i));
y = y / 2 + 0.5;
vout.setValue(y);
if (i == 359) {
i = 0;
}
}
}
示例7: initialize
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public void initialize() throws Exception {
if (this.bus == null) {
this.bus = I2CFactory.getInstance(I2CBus.BUS_1);
}
if (this.i2CDevice == null) {
this.i2CDevice = bus.getDevice(BLUEESC_ADDRESS + device);
resetEsc();
Runtime.getRuntime().addShutdownHook(new ShutdownThread());
if (this.keepAlive && keepAliveThread == null) {
this.keepAliveThread = new KeepAliveThread();
this.keepAliveThread.start();
}
}
}
示例8: getDevice
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public I2CDevice getDevice(int busAddress, int deviceAddress) {
try {
String key = String.format("%d.%d", busAddress, deviceAddress);
if (!devices.containsKey(key)) {
// FIXME -- remove put in createDevice
I2CBus bus = I2CFactory.getInstance(busAddress);
log.info(String.format("getDevice %d", deviceAddress));
I2CDevice device = bus.getDevice(deviceAddress);
Device d = new Device();
d.bus = bus;
d.device = device;
d.type = "display";
devices.put(key, d);
return d.device;
} else {
return devices.get(key).device;
}
} catch (Exception e) {
Logging.logError(e);
}
return null;
}
示例9: init
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public void init(){
try {
_gpioController = GpioFactory.getInstance();
_i2cbus = I2CFactory.getInstance(I2CBus.BUS_1);
_temperatureSensor = _i2cbus.getDevice(0x40);
_lightActuator = _gpioController.provisionDigitalMultipurposePin(RaspiPin.GPIO_00, "led", PinMode.DIGITAL_OUTPUT);
_lightActuator.setShutdownOptions(true); // unexport on shutdown
// monitor temperature changes
// every change of more than 0.1C will notify SensorChangedListeners
_scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
_handle = _scheduledThreadPoolExecutor.scheduleAtFixedRate(temperatureReader, 0, 100, TimeUnit.MILLISECONDS);
} catch (IOException e) {
log.error("An error occurred whilst trying to read temperature from GPIO Pins.");
}
}
示例10: writeToDisplay
import com.pi4j.io.i2c.I2CBus; //导入依赖的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);
}
}
示例11: testBmp180BarometricSensorNewRaspi
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
@Test
public void testBmp180BarometricSensorNewRaspi() throws IOException {
new NonStrictExpectations() {
{
I2CFactory.getInstance(withEqual(I2CBus.BUS_1));
result = i2cBus;
i2cBus.getDevice(withEqual(0x77));
result = device;
// calibration
device.read(anyInt);
result = 1;
times = 22;
}
};
Bmp180BarometricSensor sensor = new Bmp180BarometricSensor(true, 0);
assertTrue(sensor.isInitiated());
}
示例12: BME280
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public BME280() {
try {
// Create I2C bus
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get I2C device, BME280 I2C address is 0x76(108)
device = bus.getDevice(0x76);
} catch (Exception e) {
Logger.error("Failed to get BME280.");
e.printStackTrace();
}
}
示例13: createProvider
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
private PCA9685GpioProvider createProvider() throws UnsupportedBusNumberException, IOException {
BigDecimal frequency = PCA9685GpioProvider.ANALOG_SERVO_FREQUENCY;
BigDecimal frequencyCorrectionFactor = new BigDecimal("1.0578");
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
return new PCA9685GpioProvider(bus, 0x40, frequency, frequencyCorrectionFactor);
}
示例14: main
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP3424 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP3424 GPIO provider
final MCP3424GpioProvider provider = new MCP3424GpioProvider(I2CBus.BUS_1, 0x6C, 18, 1);
// provision gpio input pins from MCP3424
GpioPinAnalogInput inputs[] = { gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH0, "Channel-0"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH1, "Channel-1"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH2, "Channel-2"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH3, "Channel-3") };
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
StringBuilder sb = new StringBuilder();
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
double analog = provider.getAnalogValue(input.getPin());
sb.append(" \t[" + input.getValue() + " -> " + analog + " V] ");
}
// Print out all analog input conversion values
System.out.println("<MCP3424 VALUES> " + sb.toString());
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("<--Pi4J--> Exiting MCP3424 GPIO Example.");
}
示例15: main
import com.pi4j.io.i2c.I2CBus; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) throws Exception {
System.out.println("Starting:");
// get I2C bus instance
final I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
WiiMotionPlus wiiMotionPlus = new WiiMotionPlus(bus);
wiiMotionPlus.init();
int iteration = 0;
makeBackup("log.txt");
FileWriter logFile = new FileWriter("log.txt");
BufferedWriter bw = new BufferedWriter(logFile, 2048);
PrintWriter log = new PrintWriter(bw);
try {
while (true) {
long now = System.currentTimeMillis();
ThreeAxis threeAxis = wiiMotionPlus.read();
long lasted = System.currentTimeMillis() - now;
System.out.print(formatInt(iteration));
System.out.print(' ');
System.out.print(formatLong(lasted));
System.out.print(' ');
System.out.print(formatInt(threeAxis.x));
System.out.print(' ');
System.out.print(formatInt(threeAxis.y));
System.out.print(' ');
System.out.print(formatInt(threeAxis.z));
System.out.print(' ');
// System.out.print('\r');
System.out.println();
log.println(formatInt(iteration) + "," + formatLong(lasted) + "," + formatInt(threeAxis.x) + "," + formatInt(threeAxis.y) + "," + formatInt(threeAxis.z));
//log.flush();
Thread.sleep(500);
iteration = iteration + 1;
}
} finally {
bw.flush();
bw.close();
logFile.close();
}
}