ive been having a lot of problems with my 74595 shift registers and was wondering if anyone could help. the problem ive been having is whenever i try to blink 12 leds at a time the output freaks out and no matter what i add as a delay the output is never a 50% on 50% off cycle its actually closer to 10% 90%. if theres any more information i can provide to help solve the problem i will gladly do so.
// pin constants
int data = 2; // data pin for shift register
int clock = 3; // clock pin for shift register
int latch = 19; //latch pin shift register
int switch0 = 4; // Always on setting
int switch1 = 5; // 50/50 blink
int switch2 = 6; // mirror flop
int switch3 = 7; //neon sign
int switch4 = 8; // flip flop
int switch5 = 9; // Knight rider
int switch6 = 10; // radiance
int switch7 = 11; // random number
int timer = 100; // completely relient on the pot value
//colors
int red = 4;
int orange = 5;
int yellow = 6;
int green = 7;
int cyan = 8;
int blue = 9;
int uv = 10;
int pink = 11;
void shiftLed( int data, int clock, int latch, byte number1, byte number2)
{
digitalWrite(latch, LOW); //start listening
shiftOut(data, clock, LSBFIRST, number1);
shiftOut(data, clock, LSBFIRST, number2);
digitalWrite(latch, HIGH);//shift out
}
void setup() {
pinMode(clock, OUTPUT); //clock as output
pinMode(data, OUTPUT); //data as output
pinMode(latch, OUTPUT);// latch as output
pinMode(switch0, INPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
pinMode(switch5, INPUT);
pinMode(switch6, INPUT);
pinMode(switch7, INPUT);
}
void loop() {
if (digitalRead(orange) == LOW) // blink setting
{
shiftLed( data, clock, latch, B00000000, B00001000);
delay(timer);
shiftLed( data, clock, latch, B00000000, B00001100);
delay(timer);
shiftLed( data, clock, latch, B00000000, B00001110);
delay(timer);
shiftLed( data, clock, latch, B00000000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B10000000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11000000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11100000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11110000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111100, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111110, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111111, B00001111);
delay(timer);
//blink
// this is the part that usually goes really wrong
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
}
else //error setting that displays F42 in hex
{
shiftLed( data, clock, latch, B01000010, B11111111);
delay(250);
}
}
