import java.io.*;

import com.pi4j.io.i2c.*;


public class TwiTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TwiTest tt = new TwiTest();
		try {
			tt.run();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	void run() throws Exception {
		System.out.println("start");
    final I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
		System.out.println("habe bus");
		I2CDevice device = bus.getDevice(0x40);
		System.out.println("habe device");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = "";
    while (str != null) {
      System.out.print("Zahl?> ");
      str = in.readLine();
      byte b = Byte.parseByte(str);
      device.write(b);
  		System.out.println(b + " geschrieben");
  		int i = device.read();
  		System.out.println(i + " gelesen");
    }
	}
}
