8x8 Led matrix turn signal control by switches

My apologies - I corrected the program flow, but failed to spot the glaring typo! Picked that up on my little netbook reading in bed this morning. :smiley:

This should work now - I think!

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int inputPin2 = 2;            // input pin for left (switch) 
int inputPin3 = 3;            //input pin for right (switch)
int valleft = 0;
int valright =0;

int LEDs[8][8] = {   
  { 0, 0, 0, 0, 0, 0, 0, 0 } , //blank
  { 0, 0, 0, 0, 0, 0, 0, 0 } ,
  { 0, 0, 0, 0, 0, 0, 0, 0 } ,
  { 0, 0, 0, 0, 0, 0, 0, 0 } ,
  { 0, 0, 0, 0, 0, 0, 0, 0 } ,
  { 0, 0, 0, 0, 0, 0, 0, 0 } ,
  { 0, 0, 0, 0, 0, 0, 0, 0 } ,
  { 0, 0, 0, 0, 0, 0, 0, 0 }   
};

int right[8][8] = {   
  { 0, 0, 0, 0, 1, 0, 0, 0 } , //right signal 
  { 0, 0, 0, 0, 1, 1, 0, 0 } ,
  { 1, 1, 1, 1, 1, 1, 1, 0 } ,
  { 1, 1, 1, 1, 1, 1, 1, 1 } ,
  { 1, 1, 1, 1, 1, 1, 1, 1 } ,
  { 1, 1, 1, 1, 1, 1, 1, 0 } ,
  { 0, 0, 0, 0, 1, 1, 0, 0 } ,
  { 0, 0, 0, 0, 1, 0, 0, 0 }    
};

int left[8][8] = {   
  { 0, 0, 0, 1, 0, 0, 0, 0 } , //left signal 
  { 0, 0, 1, 1, 0, 0, 0, 0 } ,
  { 0, 1, 1, 1, 1, 1, 1, 1 } ,
  { 1, 1, 1, 1, 1, 1, 1, 1 } ,
  { 1, 1, 1, 1, 1, 1, 1, 1 } ,
  { 0, 1, 1, 1, 1, 1, 1, 1 } ,
  { 0, 0, 1, 1, 0, 0, 0, 0 } ,
  { 0, 0, 0, 1, 0, 0, 0, 0 }    
};

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(inputPin2, INPUT);
  pinMode(inputPin3, INPUT);
}

void loop() {
  int t;
  valleft = digitalRead (inputPin2);
  valright = digitalRead (inputPin3);  

  if (valleft == HIGH) {                 //when the left switch is on 
    for (t = 0; t < 64; t++) lightLED(left);  //display left signal 
    lightLED(LEDs);                      // off 
    delay(1000);
  }
  else if (valright == HIGH) {
    for (t = 0; t < 64; t++) lightLED(right);
    lightLED(LEDs);
    delay(1000);
  }
  else 
    lightLED(LEDs);
}
void lightLED(int tempLED[8][8]) {          //run the lightLED  bit by bit 
  byte columnbitsToSend = 0;
  byte rowbitsToSend = 0;

  int x;
  int y;
  for (x = 0; x < 8; x++) {
    columnbitsToSend = 0;
    rowbitsToSend = 0;

    for (y = 0; y < 8; y ++) {
      if (tempLED[x][y] == 1) {
        bitWrite(rowbitsToSend, y, HIGH);
      } 
    }

    digitalWrite(latchPin, LOW);
    bitWrite(columnbitsToSend, x, HIGH);
    shiftOut(dataPin, clockPin, MSBFIRST, columnbitsToSend);
    shiftOut(dataPin, clockPin, MSBFIRST, rowbitsToSend);
    digitalWrite(latchPin, HIGH);   
    delay(2);
  }
}

Didn't notice how badly "Auto Format" had mangled the arrays either!


And a few more bugs - wouldn't compile.