Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**************************************************************//
- // Name : shiftOutCode, Predefined Dual Array Style //
- // Author : Carlyn Maw, Tom Igoe //
- // Date : 25 Oct, 2006 //
- // Version : 1.0 //
- // Notes : Code for using a 74HC595 Shift Register //
- // : to count from 0 to 255 //
- //****************************************************************
- //Pin connected to ST_CP of 74HC595
- static int latchPin = 8;
- //Pin connected to SH_CP of 74HC595
- static int clockPin = 12;
- ////Pin connected to DS of 74HC595
- static int dataPin = 11;
- //holders for infromation you're going to pass to shifting function
- byte dataRED;
- byte dataGREEN;
- byte dataArrayRED[10];
- byte dataArrayGREEN[10];
- void setup() {
- //set pins to output because they are addressed in the main loop
- pinMode(latchPin, OUTPUT);
- Serial.begin(9600);
- //Arduino doesn't seem to have a way to write binary straight into the code
- //so these values are in HEX. Decimal would have been fine, too.
- dataArrayRED[0] = 11111111; //11111111
- dataArrayRED[1] = 11111111; //11111110
- dataArrayRED[2] = 00000000; //11111100
- dataArrayRED[3] = 11111111; //11111000
- dataArrayRED[4] = 00000000; //11110000
- dataArrayRED[5] = 11111111; //11100000
- dataArrayRED[6] = 00000000; //11000000
- dataArrayRED[7] = 11111111; //10000000
- dataArrayRED[8] = 00000000; //00000000
- dataArrayRED[9] = 11111111; //11100000
- //Arduino doesn't seem to have a way to write binary straight into the code
- //so these values are in HEX. Decimal would have been fine, too.
- dataArrayGREEN[0] = 11111111; //11111111
- dataArrayGREEN[1] = 0xFF; //01111111
- dataArrayGREEN[2] = 0xFF; //00111111
- dataArrayGREEN[3] = 0xFF; //00011111
- dataArrayGREEN[4] = 0xFF; //00001111
- dataArrayGREEN[5] = 0xFF; //00000111
- dataArrayGREEN[6] = 0xFF; //00000011
- dataArrayGREEN[7] = 0xFF; //00000001
- dataArrayGREEN[8] = 0xFF; //00000000
- dataArrayGREEN[9] = 0xFF; //00000111
- //function that blinks all the LEDs
- //gets passed the number of blinks and the pause time
- //blinkAll_2Bytes(2,500);
- //load the light sequence you want from array
- dataRED = B00000010;
- dataGREEN = B00001001;
- //ground latchPin and hold low for as long as you are transmitting
- digitalWrite(latchPin, 0);
- //move 'em out
- shiftOut(dataPin, clockPin, B11110000);
- shiftOut(dataPin, clockPin, B00010010);
- shiftOut(dataPin, clockPin, B01001001);
- shiftOut(dataPin, clockPin, B00100100);
- //return the latch pin high to signal chip that it
- //no longer needs to listen for information
- digitalWrite(latchPin, 1);
- digitalWrite(latchPin, 0);
- delay (2000);
- shiftOut(dataPin, clockPin, B11110000);
- shiftOut(dataPin, clockPin, B00011011);
- shiftOut(dataPin, clockPin, B01101101);
- shiftOut(dataPin, clockPin, B10110110);
- //return the latch pin high to signal chip that it
- //no longer needs to listen for information
- digitalWrite(latchPin, 1);
- digitalWrite(latchPin, 0);
- delay (2000);
- shiftOut(dataPin, clockPin, B11110000);
- shiftOut(dataPin, clockPin, B00001001);
- shiftOut(dataPin, clockPin, B00100100);
- shiftOut(dataPin, clockPin, B10010010);
- //return the latch pin high to signal chip that it
- //no longer needs to listen for information
- digitalWrite(latchPin, 1);
- digitalWrite(latchPin, 0);
- }
- void loop() {
- }
- // the heart of the program MSB first
- void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
- int i=0;
- int pinState;
- pinMode(myClockPin, OUTPUT);
- pinMode(myDataPin, OUTPUT);
- digitalWrite(myDataPin, 0);
- digitalWrite(myClockPin, 0);
- for (i=7; i>=0; i--) {
- digitalWrite(myClockPin, 0);
- if ( myDataOut & (1<<i) ) {
- pinState= 1;
- }
- else {
- pinState= 0;
- }
- //Sets the pin to HIGH or LOW depending on pinState
- digitalWrite(myDataPin, pinState);
- //register shifts bits on upstroke of clock pin
- digitalWrite(myClockPin, 1);
- //zero the data pin after shift to prevent bleed through
- digitalWrite(myDataPin, 0);
- }
- //stop shifting
- digitalWrite(myClockPin, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement