You're right about a bit mask. I actually haven't tried this but I believe this my be your suggestion.
/******* Set Outputs *********/
if (values[2] == 2)
{
byte byteVal = (values[0]);// Change to byte representation
if (digitalRead(zoneSwitch) != CLOSED) // No zone valve closed
{
byteVal = byteVal &= 0b11110111; // Ignore Floor pump
PORTA = ~ byteVal; //Negate or invert bits. 1 sent to turn on output is inverted to 0 to ground output and turn on relay
KeepAlive.start(0, 0, keepAliveTime, 0); // Keep alive signal from XOJO (10 Min)
offLine = false;
}
else
{
PORTA = ~ byteVal; //Negate or invert bits. 1 sent to turn on output is inverted to 0 to ground output and turn on relay
}
You stated you wanted to mask bit 3. Now you are masking bit 4... (if you start numbering at 1).
Suggestion: rename byteVal to something that makes sense. What is behind the ports? Something like pumpState would do...
Yes, is see if the bit was set it would be changed using &. It seems weird to be able to use PORT in the second half of your equation when that is what your outcome is. I hope Iām seeing that correctly.
byte myCopy = PORTD; // get the output register
myCopy &= ~mask; // set the masked bit(s) to 0
byte myNewValue = byteVal; // copy the new value
myNewValue &= mask; // set the unmasked bit(s) to 0
PORTD = myCopy | myNewValue; // combine. No conflicting bits
Where there are 1s in the mask, the bits come from byteVal.
Where there are 0s in the mask, we preserve the PORTD bits.
If mask is 0b11110111, then ~mask is 0b00001000.
In this case you could combine them with addition, as there will never be any carrying as there will not be 1s in the same bit position. But use the '|' logical or operator.