Hello everyone.
I have two things going on at one time. I have one of the analog ports controlling a Radio Shack Tri Color LED strip. I have cut the strip so that I am only running 4 sets of 3 LED's. The other task is to light up some normal 5mm LED's from the digital ports with some pattern.
I am trying to figure out how to have both of these tasks run at the same time,if possible, so one doesn't have to wait for the other to finish. I have seen ways of using millis(), but not sure how to get that incorporated into all of this.
I know the delays stop everything, so the 'void side_to_side' function is just laid out that way for an example to demonstrate what I want to do with the LED's on the digital ports, while the LED strip is doing its thing.
The attached file is a demo file from Radio Shack that I widdled down to work with my project.
It is not going to be easy to get there from here. The code you have is perfectly fine as a demo but it is obviously not intended to be used in a real environment where you have more than one thing to do.
Think of the Arduino as a man with a watch and a row of switches. He looks at the watch thousands of times per second. He's got a list in front of him which says at what time each switch is supposed to be on or off. Every time he looks at the watch, he scans down his list of times to find the appropriate line. Then he puts his fingers on the switches and pushes them - even if they were already pushed, he doesn't care, he's just following his list and he has nothing else to do except push switches.
Do you want the two subsystems synchronised or are they intended to be out of sync? (One list or two lists of times?)
You can buy the "little tiny" arduino equivalents, like the nano or the pro micro on line for about $2 apiece. At that price, break your task into two indepedent streams. If you need any communication between them, set up a serial link. Since the Rx0/Tx0 are best left for programming, use the software serial library. I have found that frequently, rather than shoehorning a complicated bunch of processes into one arduino, it is just much less time-consuming to spread the tasks out. The first time you do it, there's a bit of a learning curve, after that its easy.
im not sure if this will help but it was something used on a different post
I changed the pin numbers to the ones you has listed. This is a light chase sketch like the one you tried to write with the delays
byte ledArray[] = {2, 3, 4, 5, 6, 7,};
unsigned long previousMillis = 0;
unsigned long interval = 1000;//every second
byte ledPosition = 0;
byte prevPosition = 2;
void setup() {
Serial.begin(9600);
for (byte x = 0; x < 5; x = x + 1) {
//do this 6 times
pinMode (ledArray[x], OUTPUT);//x is going to be 0-1-2-3-4-5
}
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
//timer is done at this point
ledPosition++;//add to counter called ledPosition
previousMillis = currentMillis;//take a new time stamp
}
if (ledPosition >= 6) {//if counter is 6 change to 0
ledPosition = 0;
}
if (ledPosition != prevPosition) {//has timer changed ledPosition
//if so do this once see prevPosition = ledPosition; further down
for (byte y = 0; y < 5; y = y + 1) {//run next section of code 6 times
// each time y will be changed so 0-1-2-3-4-5
if (ledPosition == y) {//what ever number between 0 and 5 led postion is
//check against y if they are equal turn that led on
digitalWrite (ledArray[y], HIGH);
Serial.print(ledArray[y]);
Serial.println(" on");
}
else
{ //not equal turn the led off
//only one will be equal so this turns 5 off
digitalWrite (ledArray[y], LOW);
Serial.print(ledArray[y]);
Serial.println(" off");
}
}
}
prevPosition = ledPosition;//reset so above if only runs once
}