Is it possible to make a for loop where in every cycle an element from array would be printed on serial monitor and an LED would stay HIGH for a minute without delay()? Pseudo code:
void loop ()
{
for (i = 0; i < NUMBR; i++)
{
Serial.print(array[i]);
turn "ON" an LED and hold it "ON" for 1 minute for this element of array,
without writing delay(1000) in the following line, and
digitalWrite(LED, LOW) in the line after that
}
}
So lets say in array I have numbers 4,5,6. On serial monitor should be printed number 4 and at the same time LED should go "ON". On monitor number 4 should stay printed 1 minute before the next number is printed and LED should stay "ON" for 1 minute and continue like so for each number/element in array.
Sorry, forgot to say that also. It should go "OFF" after that one minute. So in short: number should stay printed for 1 minute and LED should stay "ON" for 1 minute, after that 1 minute LED should go "OFF" and the next number should be printed and LED should go "ON" again.
Sounds like the led will be on for the whole loop through the numbers - as soon as you turn it off, the sketch will loop round and turn it on again. It won't be visible until the very end assuming the led goes off for good. As you have it now of course it will just run loop over & over and the led will be on forever.
If possible, the transition should be visible. So: printed number and LED stay "ON" 1 minute, they turn "OFF", transition which is visible (a couple of seconds), next element printed and LED stay "ON" for 1 minute. All that if possible without a single delay() in a for loop.
It doesn't really matter what else is going on. The parts that happen take very little time once the time detection has occurred.
Look "20Hz" in the forum, I posted some code there that will similar to what you are trying to do - start something that runs continuously (your array reading & printing) and then a second action (your LED off time).
It's all a variation on blink without delay, some may say state-machine like.
CrossRoads:
It doesn't really matter what else is going on. The parts that happen take very little time once the time detection has occurred.
Look "20Hz" in the forum, I posted some code there that will similar to what you are trying to do - start something that runs continuously (your array reading & printing) and then a second action (your LED off time).
It's all a variation on blink without delay, some may say state-machine like.
orry, forgot to say that also. It should go "OFF" after that one minute. So in short: number should stay printed for 1 minute and LED should stay "ON" for 1 minute, after that 1 minute LED should go "OFF" and the next number should be printed and LED should go "ON" again.
Be careful what you ask for.
const int ledPin = 13;
int ledState = LOW;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 60UL * 1000UL;
int pos = 0;
int myarray[] = {5, 6, 7};
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
}
void loop(){
currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
digitalWrite(ledPin, LOW);
Serial.println(myarray[pos]);
pos = (pos + 1) % 3;
}
digitalWrite(ledPin, HIGH);
}
Don't blame me if it looks like the led is ON all the time