Here's the official page on our site:
http://www.wusik.com/ww/open-wusik/arduino/download-filesAnd here are the files.
C165.h
/*
www.Wusik.com - Created by WilliamK @ Wusik Dot Com (c) 2010
8 to 16 Inputs with only 3 pins on the Arduino using the following chip: 74HC165N
http://www.sparkfun.com/products/9519
Typical Usage:
Setup:
C165 Inputs = C165(25,27,26);
C165( Connects to Parallel load pin the 165,
Connects to the Q7 pin the 165,
Connects to the Clock pin the 165);
Loop:
if (Inputs.Tick()) // Returns True if something changed //
{
for (int xc=0; xc<16; xc++)
{
if (Inputs.isOn(xc))
{
// Do Something //
}
}
}
*/
#ifndef C165_h
#define C165_h
#define NumberOfChips 2
#include <inttypes.h>
#include "HardwareSerial.h"
class C165
{
public:
C165(byte _loadPin, byte _dataPin, byte _clockPin);
boolean Tick();
void Reset(void);
boolean isOn(byte Pos);
private:
byte loadPin;
byte dataPin;
byte clockPin;
boolean Changed;
boolean On[NumberOfChips*8];
byte tempInputs;
byte prevHigh[NumberOfChips*8];
};
#endif
C165.cpp
/*
www.Wusik.com - Created by WilliamK @ Wusik Dot Com (c) 2010
Check the C165.h file for instructions
*/
#include "WConstants.h"
#include "C165.h"
// ------------------------------------------------------------------------------------------- //
C165::C165(byte _loadPin, byte _dataPin, byte _clockPin)
{
Changed = false;
loadPin = _loadPin;
dataPin = _dataPin;
clockPin = _clockPin;
pinMode(loadPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
digitalWrite(clockPin, LOW);
digitalWrite(loadPin, HIGH);
Reset();
}
// ------------------------------------------------------------------------------------------- //
boolean C165::Tick()
{
Changed = false;
digitalWrite(loadPin, LOW);
digitalWrite(loadPin, HIGH);
for(int i = 0; i < (NumberOfChips*8); i++)
{
tempInputs = digitalRead(dataPin);
if (tempInputs == LOW && prevHigh[((NumberOfChips*8)-1)-i] == HIGH) { On[((NumberOfChips*8)-1)-i] = true; Changed = true; }
prevHigh[((NumberOfChips*8)-1)-i] = tempInputs;
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
return Changed;
}
// ------------------------------------------------------------------------------------------- //
void C165::Reset()
{
memset(On,false,sizeof(On));
memset(prevHigh,false,sizeof(prevHigh));
}
// ------------------------------------------------------------------------------------------- //
boolean C165::isOn(byte Pos)
{
if (On[Pos])
{
On[Pos] = false;
return true;
}
return false;
}
C595.h
/*
www.Wusik.com - Created by WilliamK @ Wusik Dot Com (c) 2010
8 to 16 Outputs with only 3 pins on the Arduino using the following chip: 74HC595
http://www.sparkfun.com/products/733
Typical Usage:
Setup:
C595 Outputs = C595(22,24,23);
C595(Latch Pin, Clock Pin, Data Pin)
Loop:
Outputs.setOutput(0, true);
Outputs.setOutput(1, true);
Outputs.setOutput(2, false);
...
Outputs.setOutput(15, false);
Outputs.Tick();
*/
#ifndef C595_h
#define C595_h
#define NumberOfChips 2
#include <inttypes.h>
#include "HardwareSerial.h"
// ======================================================================================= //
class C595
{
public:
C595(byte _latchPin, byte _clockPin, byte _dataPin);
void Tick(void);
void setOutput(byte Pos, boolean Value);
void Reset(void);
private:
byte latchPin;
byte clockPin;
byte dataPin;
boolean Output[NumberOfChips*8];
};
#endif
C595.cpp
/*
www.Wusik.com - Created by WilliamK @ Wusik Dot Com (c) 2010
Check the C595.h file for instructions
*/
#include "WConstants.h"
#include "C595.h"
// ------------------------------------------------------------------------------------------- //
C595::C595(byte _latchPin, byte _clockPin, byte _dataPin)
{
latchPin = _latchPin;
clockPin = _clockPin;
dataPin = _dataPin;
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Reset();
}
// ------------------------------------------------------------------------------------------- //
void C595::Tick()
{
digitalWrite(latchPin, LOW);
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, LOW);
for (int i=15; i>=0; i--)
{
digitalWrite(clockPin, LOW);
if (Output[i]) digitalWrite(dataPin, HIGH); else digitalWrite(dataPin, LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(dataPin, LOW);
}
digitalWrite(clockPin, LOW);
digitalWrite(latchPin, HIGH);
}
// ------------------------------------------------------------------------------------------- //
void C595::Reset(void)
{
memset(Output,false,sizeof(Output));
}
// ------------------------------------------------------------------------------------------- //
void C595::setOutput(byte Pos, boolean Value)
{
Output[Pos] = Value;
}