yogi wrote:void setup ()
{
pinMode(x, INPUT); // for all the CD4021 pins
PORTB &= b00000000; // Arduino pins 8, 9, 10 and 11; PB0:PB3 to Hi-Z inputs
PORTC &= b00000000; // Arduino pins A0, A1, A2 and A3; PC0:PC3 to Hi-Z inputs
}Not to nit-pick, because I know you were just typing this off the top of your head, but I think what you mean is:
PORTB &= ~B00001111;
PORTC &= ~B00001111;to set only those pins to '0'
yogi wrote:DDRB = (1 << PBx) // Change pin to output
DDRB = (0 << PBx) // Change pin to Hi-Z inputagain:
DDRB |= (1 << PBx);
DDRB &= ~(1 << PBx);to affect only that pin, otherwise you are changing all of the bits on that port, and with Arduinos that can be bad when some of them are permanently assigned as reset or crystal pins...
Glad you caught this,Thanks. sorry for my confusion.
My poor C skills are showing Let this be a lesson: 'Compound bitwise logic and late night posting don't mix'!