I having a problem with my right and left signal.
I connect the 8x8 LED matrix to 2 shift register.
I desire to create a code with (left switch on) left signal on for 1 second then off for 1 second and keep repeat. This goes same to right switch.
This is my code. The output of this code is when left switch on the left signal blinking very fast. The blinking rate as i desire is 1 sec for on and off.
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() {
valleft = digitalRead (inputPin2);
valright = digitalRead (inputPin3);
if (valleft == HIGH) { //when the left switch is on
lightLED(left); //display left signal
delay(1000); //waits for 1 sec ( this code seem like not working)
lightLED(LEDs); // off
delay(1000):
}
else if (valright == HIGH) {
lightLED(right);
delay(1000);
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 = 0;
int y = 0;
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);
}
}
(code tags added by moderator)