questions about tick and adding debounce

Im fairly new to this and im trying to use a 74HC165 and a 74HC595 to be able to control leds and relays over very few wires. i finally got it working using a example. The example code has a "tick" command im not familiar with. The code works but i was wanting to only make 1-4 turn off after i release the button on the 165 and add debounce to 5-8.

almost.ino (436 Bytes)

The example code has a "tick" command im not familiar with.

Tick is a library function in the physical file C165.cpp
Here is the relevant partial code:

unsigned int C165::tick()
{
	uint8_t tempInputs;
	prevvalues = values;

	digitalWrite(loadPin, LOW);
	digitalWrite(loadPin, HIGH);
	for(int i=((chips*8)-1); i >= 0; i--)
	{
		tempInputs = digitalRead(dataPin);
		if (tempInputs == LOW && bitRead(prevhigh,i) > 0) bitSet(values,i);
		bitWrite(prevhigh,i,tempInputs);

		digitalWrite(clockPin, HIGH);
		digitalWrite(clockPin, LOW);
	}

	return values ^ prevvalues;	// X-or
}
/*
 
    Created by WilliamK @ Wusik Dot Com (c) 2010
    http://arduino.wusik.com
 
*/

#include <C165.h>
#include <C595.h>

C165 WButtons = C165(13,8,10,1);
C595 WLEDs = C595(11,10,9,1);

unsigned int WLEDsTemp = 0;
unsigned int WButtonsTemp = 0;

void setup() 
{
  //
}

void loop() 
{
  WButtonsTemp = WButtons.tick();
  if (WButtonsTemp)
  {
    WLEDsTemp ^= WButtonsTemp;
    WLEDs.tick(WLEDsTemp);  
    WButtons.reset();
  }
}

there has to be some simpler way to shiftIN and shiftOUT, this sketch isnt working. Im trying to have it when input is HIGH output is HIGH and when input is LOW output is LOW. This sketch is acting liking a switch, i have to bring it HIGH again to bring the output to LOW

Some working code for 74HC165

And the 595

yes these are the codes im using and got them combined, but i need output to be low when input is low