document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  Demo Code for HDSP 2111 using SN74LS595N
  3.  Matt Joyce < matt@nycresistor.com >
  4.  Mark Tabry
  5.  */
  6.  
  7. //Pin connected to latch pin (ST_CP) of 74HC595
  8. const int latchPin = 8;
  9. //Pin connected to clock pin (SH_CP) of 74HC595
  10. const int clockPin = 12;
  11. ////Pin connected to Data in (DS) of 74HC595
  12. const int dataPin = 11;
  13. const int ce = 5;
  14. const int wr = 6;
  15. const int a2 = 4;
  16. const int a1 = 3;
  17. const int a0 = 2;
  18. const int rst = 10;
  19. const int a3 = 9;
  20. int incomingByte = 0;
  21.  
  22. void setup() {
  23.   //set pins to output because they are addressed in the main loop
  24.   pinMode(latchPin, OUTPUT);
  25.   pinMode(dataPin, OUTPUT);  
  26.   pinMode(clockPin, OUTPUT);
  27.   pinMode(a0, OUTPUT);
  28.   pinMode(a1, OUTPUT);
  29.   pinMode(a2, OUTPUT);
  30.   pinMode(a3, OUTPUT);
  31.   pinMode(rst, OUTPUT);
  32.   pinMode(ce, OUTPUT);
  33.   pinMode(wr, OUTPUT);
  34.   digitalWrite(ce, HIGH);
  35.   digitalWrite(wr, HIGH);
  36.  
  37.   resetDisplay();
  38. }
  39.  
  40. void resetDisplay() {
  41.   digitalWrite(rst, LOW);
  42.   delayMicroseconds(1);
  43.   digitalWrite(rst,HIGH);
  44.   delayMicroseconds(150);
  45.   digitalWrite(a3, HIGH);
  46. }  
  47.  
  48. void writeDisplay(char *input) {
  49. //  Serial.println(input);
  50.   for (int i=0; i<8; i++) {    
  51.     digitalWrite(a0, (1&i)!=0?HIGH:LOW);
  52.     digitalWrite(a1, (2&i)!=0?HIGH:LOW);
  53.     digitalWrite(a2, (4&i)!=0?HIGH:LOW);
  54.        
  55.     digitalWrite(latchPin, LOW);
  56.     shiftOut(dataPin, clockPin, MSBFIRST, input[i] );
  57.     digitalWrite(latchPin, HIGH);
  58.     delay(1);    
  59.     digitalWrite(ce, LOW);
  60.     delay(1);
  61.     digitalWrite(wr, LOW);
  62.     delay(1);
  63.     digitalWrite(wr, HIGH);
  64.     delay(1);
  65.     digitalWrite(ce, HIGH);
  66.     delay(1);
  67.   }
  68. }
  69.  
  70. void scrollDisplay(char *words) {
  71.   char buffer[9];
  72.   int i = 0;
  73.   while(words[i] != 0){
  74.     boolean blank = false;
  75.     for (int j = 0; j<8; j++) {
  76.       if ( !blank && words[i+j] == 0 ) {
  77.         blank = true;
  78.       }
  79.      
  80.       if ( blank ) {
  81.         buffer[j] = \' \';
  82.       }
  83.       else {
  84.         buffer[j] = words[i+j];
  85.       }
  86.     }
  87.     buffer[8]=0;
  88.     writeDisplay(buffer);
  89.     delay(200);
  90.     i++;
  91.  }
  92.  
  93. }
  94.  
  95. void loop() {
  96.     char intro[] = "        Number 9 ";
  97.     scrollDisplay(intro);
  98.     delay(2000);
  99. }
');