//**************************************************************// // 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 int latchPin = 8; //Pin connected to SH_CP of 74HC595 int clockPin = 12; ////Pin connected to DS of 74HC595 int dataPin = 11; //holders for infromation you're going to pass to shifting function byte data; byte dataArrayseg1[10]; byte dataArrayseg2[10]; byte dataArrayseg3[10]; byte dataArrayseg4[10]; byte puntos[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. dataArrayseg1[0] = B01101111; dataArrayseg1[1] = B00000011; dataArrayseg1[2] = B01011101; dataArrayseg1[3] = B01010111; dataArrayseg1[4] = B00110011; dataArrayseg1[5] = B01110110; dataArrayseg1[6] = B01111110; dataArrayseg1[7] = B01000011; dataArrayseg1[8] = B01111111; dataArrayseg1[9] = B01110111; //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. puntos[0] = B00000000; puntos[1] = B00000001; puntos[2] = B00000000; puntos[3] = B00000001; puntos[4] = B00000000; puntos[5] = B00000001; puntos[6] = B00000000; puntos[7] = B00000001; puntos[8] = B00000000; puntos[9] = B00000001; dataArrayseg2[0] = B11011110; dataArrayseg2[1] = B00000110; dataArrayseg2[2] = B10111010; dataArrayseg2[3] = B10101110; dataArrayseg2[4] = B01100110; dataArrayseg2[5] = B11101100; dataArrayseg2[6] = B11111100; dataArrayseg2[7] = B10000110; dataArrayseg2[8] = B11111110; dataArrayseg2[9] = B11101110; dataArrayseg3[0] = B01111011; dataArrayseg3[1] = B01100000; dataArrayseg3[2] = B01011101; dataArrayseg3[3] = B01110101; dataArrayseg3[4] = B01100110; dataArrayseg3[5] = B00110111; dataArrayseg3[6] = B00111111; dataArrayseg3[7] = B01100001; dataArrayseg3[8] = B01111111; dataArrayseg3[9] = B01110111; dataArrayseg4[0] = B01111011; dataArrayseg4[1] = B01100000; dataArrayseg4[2] = B01011101; dataArrayseg4[3] = B01110101; dataArrayseg4[4] = B01100110; dataArrayseg4[5] = B00110111; dataArrayseg4[6] = B00111111; dataArrayseg4[7] = B01100001; dataArrayseg4[8] = B01111111; dataArrayseg4[9] = B01110111; //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_4Bytes(2,500); } void loop() { for (int j = 0; j < 10; j++) { digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, dataArrayseg1[j]); data=dataArrayseg2[j]|puntos[j]; shiftOut(dataPin, clockPin, data); shiftOut(dataPin, clockPin, dataArrayseg3[j]); shiftOut(dataPin, clockPin, dataArrayseg4[j]); digitalWrite(latchPin, 1); delay(1000); } } // the heart of the program void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut� //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1<