int latchPin = 5; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 6; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 4; // Data pin of 74HC595 is connected to Digital pin 4
int t=0;
byte leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off
int num1[10][7] = { { 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,0,0,1,1 }}; // 9
int num[16][1] = { { 63}, // 0
{48 }, // 1
{ 109 }, // 2
{ 121 }, // 3
{114 }, // 4
{ 91 }, // 5
{ 95 }, // 6
{ 49}, // 7
{127 }, // 8
{ 115 }, // 9
{119 }, //A
{94 }, //b
{15 }, //C
{124 }, //D
{79 }, //E
{71 }, //F
} ;
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
}
/*
* loop() - this function runs over and over again
*/
void loop()
{
/*leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
updateShiftRegister();
delay(100);
for (int i = 0; i < 5; i=i+1) // Turn all the LEDs ON one by one.
{
bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(100);
}
digitalWrite(latchPin, HIGH);
*/
//count up routine
for (int j = 0; j < 16; j=j+1) {
//ground latchPin and hold low for as long as you are transmitting
//digitalWrite(latchPin, LOW);
//shiftOut(dataPin, clockPin, LSBFIRST, j);
leds=num[j][0];
//leds=63;
//bitSet(leds,3);
//t=bitSet(leds,j);
Serial.print( leds);
Serial.print( " ");
Serial.print(j);
Serial.print(" ");
Serial.println( leds,BIN);
updateShiftRegister();
//return the latch pin high to signal chip that it
//no longer needs to listen for information
//digitalWrite(latchPin, HIGH);
delay(500);
}
}
/*
* updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'latchPin' high again.
*/
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}