Hey
I'm trying to control two sets of LEDs with two shift registers using the millis function, but I'm having trouble controlling them separately because (I think) there is a delay command in my code which doesn't work with the millis function.
So what I want to do is to do one thing with one set of LEDs and another thing with another set of LEDs at the same time.
I've been struggling with this for a while, realizing the delay command is messing everything up because the program wants to run the sequence for the first shift register, finish it, and then start the sequence on the second register instead of running them simultaneously.
This is what I've got so far:
int i, time = 100;
const unsigned long firstinterval = 10UL ;
const unsigned long secondinterval = 10UL ;
// Variable holding the timer value so far. One for each "Timer"
unsigned long firsttimer = 0 ;
unsigned long secondtimer = 0 ;
void setup() {
pinMode(8, OUTPUT); //latchPin = 8;
pinMode(12, OUTPUT); //clockPin = 12;
pinMode(11, OUTPUT); //dataPin = 11;
pinMode(9, OUTPUT); //latchPin = 9;
pinMode(13, OUTPUT); //clockPin = 13;
pinMode(7, OUTPUT); //dataPin = 7;
firsttimer = millis () ;
secondtimer = millis () ;
}
void loop() {
if ( (millis () - firsttimer) >= firstinterval ) {
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B00000000);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B10000000);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11000000);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11100000);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11110000);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11111000);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11111100);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11111110);
digitalWrite(8, HIGH);
delay(time);
digitalWrite(8, LOW);
shiftOut(11, 12, MSBFIRST, B11111111);
digitalWrite(8, HIGH);
delay(time);
// Reset timer
firsttimer = millis () ;
}
if ( (millis () - secondtimer) >= secondinterval ) {
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 128);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 64);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 32);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 16);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 8);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 4);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 2);
digitalWrite(9, HIGH);
delay(time);
digitalWrite(9, LOW);
shiftOut(7, 13, MSBFIRST, 1);
digitalWrite(9, HIGH);
delay(time);
// reset timer
secondtimer = millis () ;
}
}
I used this Arduino Forum as my blueprint.
Is there any way to get rid of the delay part of the shiftout? Or some other solution that would work?
Any help would be greatly appreciated.