dotmatrixdesign: Twitter LED Scroller Build Log

davidnin1 [ at ] gmail.com
Dec 04
Permalink

Then I write a bit of Arduino code:



//Very initial code borrowed from this example:
//**************************************************************//
//  Name    : shiftOutCode, Hello World                         //
//  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 = 9;
//Pin connected to SH_CP of 74HC595
int clockPin = 8;
////Pin connected to DS of 74HC595
int dataPin = 11;

int enablePin = 10; //Active Low!

//int col[5] = {6,5,2,3,4};
int col[5] = {4,3,2,5,6};

byte row;

byte pattern[80];

byte frame[5] =  {B00010000,
                  B00010000,
                  B00010000,
                  B00010000,
                  B00010000,
                 };

int i;
int cycles = 0;
int framenum = 0;

int totalframes = 100;

int newline;
int reading_flag = 0;
int readindex = 0;
unsigned long read_timeout;
unsigned long req_timeout = 0;
int nextcheck = 1000;

//——States——
int state = 0;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(enablePin, OUTPUT);

  for(i = 0; i    pinMode(col[i], OUTPUT);
  } 
 
 
    Serial.begin(9600);
}

void loop() {


      for (int j = 0; j  
        //Set all the column registers high, except the columnwe want to show
        for(i = 0; i          digitalWrite(col[i], HIGH);
        } 
        digitalWrite(col[j],LOW);
       
        //ground latchPin and hold low for as long as you are transmitting
        digitalWrite(latchPin, LOW); 
        //disable the outputs while we are shifting
        digitalWrite(enablePin, HIGH);
   
        shiftOut(dataPin, clockPin, MSBFIRST, frame[j]);
        //return the latch pin high to signal chip that it
        //no longer needs to listen for information
        digitalWrite(latchPin, HIGH);
        //enable the outputs
        digitalWrite(enablePin, LOW);
        delay(1);
        //digitalWrite(col[j],HIGH);
       
      }//done displaying frame
     

      if (Serial.available() > 0) {
        newline = Serial.read();
        for (int j = 0; j            frame[j] = frame[j]         }
     
        frame[0] = frame[0] | (newline & 1) == 1;
        frame[1] = frame[1] | (newline & 2) == 2;
        frame[2] = frame[2] | (newline & 4) == 4;
        frame[3] = frame[3] | (newline & 8) == 8;
        frame[4] = frame[4] | (newline & 16) == 16;
     
      }
 
}