TPIC6B595 Power Logic 8-Bit Sift Register

Used Products:

1. Arduino UNO
2. TPIC6B595N

Content:

Çeşme: http://forum.arduino.cc/index.php?topic=89684.0

Code:

/* Shift Register Example for TPIC6B595 shift register by Jens C Brynildsen This sketch turns reads serial input and uses it to set the pins of a TPIC6B595 shift register. Hardware: * TPIC6B595 shift register attached to pins 7, 8, 11 and 12 of the Arduino, as detailed below. * LEDs attached to each of the outputs of the shift register Based on the example created 23 Mar 2010 by Tom Igoe */ //Pin connected to latch pin (RCK) of TPIC6B595 const int latchPin = 8; //Pin connected to clock pin (SRCK) of TPIC6B595 const int clockPin = 12; ////Pin connected to Data in (SER IN) of TPIC6B595 const int dataPin = 11; int counter = 0; int numLedsInUse = 8; void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); Serial.begin(9600); Serial.println("*"); // delay a little and then set delay(100); } void loop() { // Display LED's running if( counter >= (numLedsInUse-1) ){ counter = 0; } else { counter++; } // write to the shift register with the correct bit set high: registerWrite(counter, HIGH); delay( 100 ); } // This method sends bits to the shift register: void registerWrite(int whichPin, int whichState) { Serial.print("whichPin: "); Serial.print(whichPin); Serial.print(", "); // the bits you want to send byte bitsToSend = 0; // write number as bits bitWrite(bitsToSend, whichPin, whichState); // turn off the output so the pins don't light up // while you're shifting bits: digitalWrite(latchPin, LOW); Serial.print("bitsToSend: "); Serial.print(bitsToSend); Serial.println(""); // shift the bits out shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); // turn on the output so the LEDs can light up: digitalWrite(latchPin, HIGH); }