Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MrAwesome14/29806b14e2e1586b6c5c to your computer and use it in GitHub Desktop.
Save MrAwesome14/29806b14e2e1586b6c5c to your computer and use it in GitHub Desktop.
//**************************************************************//
// Name : shiftOutCode, Hello World
// Author : Carlyn Maw,Tom Igoe, David A. Mellis
// Date : 25 Oct, 2006
// Modified: 26 Sep 2013
// Version : 2.0
// Notes : Code for using a 74HC595 Shift Register //
// : to show POV persistence of vision
// http://arduino.cc/en/Tutorial/ShiftOut
// using this sample code http://paulsarduino.co.uk/?page_id=50
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 10;
////Pin connected to DS of 74HC595
int dataPin = 6;
int A[] = { 8,
0b11000000,
0b01110000,
0b00101100,
0b00100110,
0b00111000,
0b11100000,
0b10000000,
0b00000000,
};
int R[] = { 7,
0b11111110,
0b00010010,
0b00010010,
0b00110010,
0b11011110,
0b10000000,
0b00000000,
};
int I[] = { 2,
0b11111110,
0b00000000,
};
int E[] = { 6,
0b11111110,
0b10010010,
0b10010010,
0b10010010,
0b10010010,
0b00000000,
};
int L[] = { 5,
0b11111110,
0b10000000,
0b10000000,
0b10000000,
0b00000000,
};
int sp[] = { 5,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
};
// output tracking vars
int iMsgIndex;
int iCharIndex;
int iCharLen;
int* iMsg[] = {A, R, I, E, L, sp};
int iMsgLen = 3;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
iMsgIndex = 0;
iCharIndex = 1;
iCharLen = iMsg[iMsgIndex][0];
}
void sendByteOut(int value) {
digitalWrite(latchPin, LOW); // set the strobe LOW
shiftOut(dataPin, clockPin, LSBFIRST, value);
digitalWrite(latchPin, HIGH);
delayMicroseconds(100);
digitalWrite(latchPin, LOW);
}
void loop() {
sendByteOut(iMsg[iMsgIndex][iCharIndex]);
delay(3);
iCharIndex++;
if (iCharIndex == iCharLen) {
iCharIndex = 1;
iMsgIndex++; // next letter
}
if (iMsgIndex == iMsgLen) {
iMsgIndex = 0;
}
iCharLen = iMsg[iMsgIndex][0];
// // count from 0 to 255 and display the number
// // on the LEDs
// for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
// // take the latchPin low so
// // the LEDs don't change while you're sending in bits:
// digitalWrite(latchPin, LOW);
// // shift out the bits:
// shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
//
// //take the latch pin high so the LEDs will light up:
// digitalWrite(latchPin, HIGH);
// // pause before next value:
// delay(200);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment