const int bits = 16; // 2x8 bit registers dasy changed is 16 bits, 1st 1/0 pin is pin 0 so you would have 0..15, 0 being the 1st led being connected to pin 0 and 16th connected to pin 15
const int steps = 14; // calculation bug somewhere, should be able to be 15 i know the problem
int latchPin = 8; //Pin connected to ST_CP(pin 12) of 74HC595
int clockPin = 12; //Pin connected to SH_CP(pin 11) of 74HC595
int dataPin = 11; //Pin connected to DS(pin 14) of 74HC595
int seq[] = {2,4,6,8,10,12,14,16,14,12,10,8,6,4,2}; // the animation (sequence). Finish sequence
int i = -1;
int whatLED;
void setup() {
// Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop(){
if(i >= steps) {
i = -1;
}
i++;
whatLED = seq[i];
int a = -1;
while(a < whatLED){
a++;
if(a == whatLED) {
add();
}
else {
skip();
}
} // 16 2
int b = bits - seq[i];
int c = 0;
while(c < b) {
c++;
// Serial.println("filling Gaps..."); // debugging
skip();
}
digitalWrite(latchPin, HIGH); // Latch it all in (turn leds on).
delay(100);
cleanUp(); // Clear out all registers
digitalWrite(latchPin, HIGH);
delay(10);
}
void add() {
digitalWrite(latchPin, LOW);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, HIGH);
delay(1);
digitalWrite(clockPin, HIGH);
delay(1);
}
void skip() {
digitalWrite(latchPin, LOW);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
delay(1);
digitalWrite(clockPin, HIGH);
delay(1);
}
void cleanUp() {
int c = -1;
while(c < bits) { //+1 makes sure we totaly clear the registers!
c++;
digitalWrite(latchPin, LOW);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
delay(1);
digitalWrite(clockPin, HIGH);
delay(1);
}
digitalWrite(latchPin, HIGH);
}
The problem I have here is not that the code doesn't works, it works almost perfectly i have 2 bugs to iron out (one minor, who cares).
the big problem currently is that I have the Serial.begin(...); un-commented or the leds wont flash at all, what gets me is that this system does not require any input from a computer or any other module.
I think the problem is that I'm trying to flash the 1/0 pins to fast and the HIGH/LOW I'm sending is not getting enough time to register, but as soon as Serial.begin is un-commented (not the println ones) it works perfectly but is slow as I'm doing an animation on what will be a 8x8 LED cube.
currently going up and down 2 595 shift registers with 16 LEDs.
Another thought now is that I'm using a pin that stuffs up without Serial being active?
yes, the code is messy