Skip to content

Option to also use arduino ports? #13

Open
@salautom

Description

@salautom

I made some modifications for myself because I need a keypad of 10 rows and 8 columns

maybe an option to add this to your code??

byte colPins[COLS] = {-4, -5, -6}; //connect to the column pinouts of the keypad (negative values are ports on the arduino itself)
negative numbers are arduino pins.

modified 3 functions:

// individual pin setup - modify pin bit in IODIR reg.
void Keypad_MC17::pin_mode(byte pinNum, byte mode) {
if (pinNum > 127)
{
pinMode(abs(pinNum-256), mode);
}
else
{
word mask = 0b0000000000000001 << pinNum;
if( mode == OUTPUT ) {
iodir_state &= ~mask;
} else {
iodir_state |= mask;
} // if mode
_wire->beginTransmission((int)i2caddr);
_wire->write( IODIRA );
_wire->write( lowByte( iodir_state ) );
_wire->write( highByte( iodir_state ) );
_wire->endTransmission();
}
} // pin_mode( )

void Keypad_MC17::pin_write(byte pinNum, boolean level) {
if (pinNum > 127)
{
digitalWrite(abs(pinNum-256), level ? HIGH : LOW);
}
else
{
word mask = 1<<pinNum;
if( level == HIGH ) {
pinState |= mask;
} else {
pinState &= ~mask;
}
port_write( pinState );
}
} // MC17xWrite( )

int Keypad_MC17::pin_read(byte pinNum) {
if (pinNum > 127)
{
return digitalRead(abs(pinNum-256));
}
else
{
_wire->beginTransmission((int)i2caddr);
_wire->write( GPIOA );
_wire->endTransmission( );
word mask = 0x1<<pinNum;
_wire->requestFrom((int)i2caddr, 2);
word pinVal = 0;
pinVal = _wire->read( );
pinVal |= ( _wire->read( )<<8 );
pinVal &= mask;
if( pinVal == mask ) {
return 1;
} else {
return 0;
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions