Keypad() function modified v.1

From Reef Projects

Jump to: navigation, search

I had to modify the LCDI2C library to make it do what I wanted with the keypad. In the file LCDI2C.cpp, I changes the keypad function to the code below. Also, I found you must delete the file "LCDI2C.o" for the changes to take effect.

int LCDI2C::keypad (){

  int data = 0;
  int val = 0;

  //  Send Keypad read command
  Wire.beginTransmission(g_i2caddress);
  Wire.send(0xFE);
  Wire.send(0x1B);
  Wire.endTransmission();
  delay(CMDDELAY);
  
  //  Connect to device and request byte
  Wire.beginTransmission(g_i2caddress);
  Wire.requestFrom(g_i2caddress, 1);

  if (Wire.available()) {
    data = Wire.receive();
  }
switch(data){
case 0:
	val = -1;
	break;
case 1:
	val = 1;
	break;
case 2:
	val = 2;
	break;
case 3:
	val = 3;
	break;
case 4:
	val = 100;
	break;
case 5:
	val = 4;
	break;
case 6:
	val = 5;
	break;
case 7:
	val = 6;
	break;
case 8:
	val = 101;
	break;
case 9:
	val = 7;
	break;
case 10:
	val = 8;
	break;
case 11:
	val = 9;
	break;
case 12:
	val = 102;
	break;
case 13:
	val = 104;
	break;
case 14:
	val = 0;
	break;
case 15:
	val = 105;
	break;
case 16:
	val = 103;
	break;
default:
	val = -1;
}

return val;
}
Personal tools