Project 20 In Beginning Arduino tweaking?(solved)

Hi all,
I am still learning by reading the book “Beginning Arduino” by Michael Mc Roberts…Project 20 uses an 8x8 LED matrix and two 74HC595 shift registers…My LED matrix was not the same as the authors original sketch so I modified the sketch to make it work…It is supposed to be a rolling wheel that scrolls from left to right across the matrix…No Problem that works as intended…I then decided to see If I could replace the wheel with my initials…The code for the two dimensional array was modified so as to display my initials(jp)…That worked perfectly also… Now that all is working, I wonder if I can scroll instead of left to right, scroll right to left…I tried various things but evidently yet do not have enough understanding how to do that…It would seem an easy task but
more than I can apparently figure out…
Can someone look at this code and point if and how this can be done?..
I thank you all for reading this and I appreciate any pointers you can offer…
Jolphil

/ Project 20
#include <TimerOne.h>

int latchPin = 8; //Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11; //Pin connected to Pin 14 of 74HC595 (Data)
byte frame = 0;  // variable to store the current frame being displayed

byte led[8][8] = { {0, 120, 72, 120, 8, 10, 14, 0}, // 8 frames of an animation
                      {0, 120, 72, 120, 8, 10, 14, 0},
                      {0, 120, 72, 120, 8, 10, 14, 0},
                      {0, 120, 72, 120, 8, 10, 14, 0},
                      {0, 120, 72, 120, 8, 10, 14, 0},
                      {0, 120, 72, 120, 8, 10, 14, 0},
                      {0, 120, 72, 120, 8, 10, 14, 0},
                      {0, 120, 72, 120, 8, 10, 14, 0} };

void setup() {
        pinMode(latchPin, OUTPUT);  // set the 3 digital pins to outputs
        pinMode(clockPin, OUTPUT);
        pinMode(dataPin, OUTPUT);

        Timer1.initialize(10000); // set a timer of length 10000 microseconds 
        Timer1.attachInterrupt(screenUpdate); // attach the screenUpdate function
}

void loop() {
        for (int i=0; i<8; i++) { // loop through all 8 frames of the animation
                for (int j=0; j<8; j++) { // loop through the 8 rows per frame
                        led[i][j]= led[i][j] << 1 | led[i][j] >> 7; // bitwise rotation
                }
        }
        frame++; // go to the next frame in the animation
        if (frame>7) { frame =0;} // make sure we go back to frame 0 once past 7
        delay(250); // wait a bit between frames
}

void screenUpdate() { // function to display image
        byte row = B10000000; // row 1
        for (byte k = 0; k < 9; k++) {
          digitalWrite(latchPin, LOW); // open latch ready to receive data

                shiftIt(~led[frame][k] ); // LED array (inverted)
                shiftIt(row); // row binary number

                // Close the latch, sending the data in the registers out to the matrix
                digitalWrite(latchPin, HIGH);
                row = row >> 1; // bitshift right
        }
}

void shiftIt(byte dataOut) {
        // Shift out 8 bits LSB first, on rising edge of clock

        boolean pinState; 

        //clear shift register read for sending data
        digitalWrite(dataPin, LOW);

        // for each bit in dataOut send out a bit
        for (int i=0; i<8; i++)  {
                //set clockPin to LOW prior to sending bit
                digitalWrite(clockPin, LOW);

                // if the value of DataOut and (logical AND) a bitmask
                // are true, set pinState to 1 (LOW)
                if ( dataOut & (1<<i) ) {
                        pinState = LOW;
                }
                else {
                        pinState = HIGH;
                }

                //sets dataPin to HIGH or LOW depending on pinState
                digitalWrite(dataPin, pinState);
                //send bit out on rising edge of clock 
                digitalWrite(clockPin, HIGH);
                digitalWrite(dataPin, LOW);
        }

digitalWrite(clockPin, LOW); //stop shifting
}

Hello again,
I thought I had tried everything to change the image scroll from going left to right to right to left..
I read the book sketch over and over, then the "light went on"
All I needed to do was to change the bit rotation..
How simple was that?...Works like a charm..Why is it that difficult problems seem impossible until you find a simple solution. I guess that's the learning process..
Thank You for this forum and many helpful members..
jolphil

Glad we could help :slight_smile:

Often just describing a problem leads you to the answer.


Rob