/* A simple programm to display mindsensors.com's acceleration sensor (ACCL-NX-v2) values on the NXT's screen.. author: Jan-Klaas Kollhof last changed by: $LastChangedBy$ last changed date: $Date$ revision: $Revision$ */ int getI2CRegister(byte sensorPort, byte i2cAddress, byte registerAddr, byte readSize) { int result = -1; byte readBuffer[]; byte msg[]; ArrayBuild(msg, i2cAddress, registerAddr); if(I2CBytes(sensorPort, msg, readSize, readBuffer)){ result = readBuffer[0]; if(readSize == 2){ //lets create a 16 bit value result = result + readBuffer[1] * 256; } } return result; } task main(){ SetSensorType(IN_2, SENSOR_TYPE_LOWSPEED); //SetSensorLowspeed(IN_1); while(1){ TextOut(0, LCD_LINE1, "x", true); TextOut(0, LCD_LINE2, "y"); TextOut(0, LCD_LINE3, "z"); int t = getI2CRegister(IN_2, 0x02, 0x42, 1); NumOut(70, LCD_LINE1, t); t = getI2CRegister(IN_2, 0x02, 0x43, 1); NumOut(70, LCD_LINE2, t); t = getI2CRegister(IN_2, 0x02, 0x44, 1); NumOut(70, LCD_LINE3, t); Wait(500); } }