flashing LED during one time loop

Hello forum,

I am another newbie, trying to use these amazing mini computers to help me with interesting projects. I have copied all my code below, it is probably terrible, but it seems to work. I am building a butane sensor for use in a boat that has a gas cooker. My code and the electronic circuit work well which is exciting. The sensor needs a few minutes to warm up, so every time I visit the boat and am preparing to set off I need a delay of several minutes whilst the sensor gets volts and gets hot. During this time I'd like to make my green LED flash - so I know it is in the warm up period. At the moment I am struggling to make this happen as a one off event. Could anyone guide me in the right direction?

Many thanks,

G


// pin8 red
int pin8 = 8;
// pin7 green
int pin7 = 7;
// pin9 yellow
int pin9 = 9;
// Analog pin 0 will be called 'sensor'
int sensor = A0;
// Set the initial sensorValue to 0
int sensorValue = 0;
//set up pot
int pot = A1;
bool warmUp;
bool warmUp2;


void setup() {
  Serial.begin(9600);
  
  pinMode(pin8, OUTPUT); //red LED
  pinMode(pin7, OUTPUT); //green LED
  pinMode(pin9, OUTPUT); //yellow LED

  //sets all led to off
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(9, HIGH);

  warmUp = true; // warm up is about to happen
      Serial.println("Warm up");
}


void loop() {

if (warmUp)  {
    delay(2000);
    digitalWrite(pin9, LOW); // turn led off 
    warmUp = false;  // prevent this code being run more then once
    Serial.println("Warm up complete");
  }




  digitalWrite(7, HIGH);
  int potValue = analogRead(A1);
  float potVoltage = (potValue/1024.0) * 5.0;
  int sensorValue = analogRead(sensor);
  float sensorMultiply = (sensorValue * 5);
  float combined = (potVoltage+sensorMultiply);

  Serial.println(" __start__ ");
  Serial.print(" pot: ");
  Serial.println(potValue); 
  Serial.print(" pot voltage: ");
  Serial.println(potVoltage); 
    Serial.println(" ");
  Serial.print(" sensor: ");
  Serial.println(sensorValue);
  Serial.print(" sensor multiply: ");
  Serial.println(sensorMultiply);
    Serial.println(" ");
  Serial.print(" combined: ");
  Serial.println(combined); 
    Serial.println(" ");
  Serial.println(" __end__ ");
     Serial.println(" ");


  // If pot+sensorValue is greater than 10
  if (combined > 100) {
    // Activate digital output pin 8 - the LED will light up
    digitalWrite(pin8, HIGH);
  }
  else {
    // Deactivate digital output pin 8 - the LED will not light up
    digitalWrite(pin8, LOW);
  }
//delay for com write
  delay(980);
  
}

You can use millis to measure how much time has passed since the Arduino was powered up.
if it's less than the warm up period, flash the green LED. After that, don't.

Or have a integer counter. If the counter is not zero, flash the led, wait 1 second, decrement the counter.
When the counter is zero do your main processing instead.

Simple code from a simple mind. :slight_smile:

unsigned long start, end = 3UL * 60 * 1000; // 3 minutes

void setup()
{
  pinMode(LED_BUILTIN,OUTPUT);
}
void loop()
{
  if(millis() - start < end) // flash LED at 512 ms rate    
    digitalWrite(LED_BUILTIN,! bitRead(millis(),9));
}

If you want to wait for a set amount of time before doing anything, wait in startup(). BTW, declaring variables with names line pin7 defeats the purpose of using “variables”.

// warm up time in seconds
const byte WARM_UP_SECONDS = 10;
const unsigned long WARM_UP_TIME = (WARM_UP_SECONDS * 1000UL);

const int WARM_UP_BLINK = 250;  // ms to blink on/off

const byte GREEN_PIN = 13;

void setup() {

  Serial.begin(9600);
  pinMode(GREEN_PIN, OUTPUT);

  Serial.print("Warm up started ...");

  // time we've spent warming up
  unsigned long totalTime = 0UL;

  // stay here until warm up complete
  while ( totalTime < WARM_UP_TIME )
  {
    // toggle LED
    digitalWrite(GREEN_PIN, !digitalRead(GREEN_PIN));

    delay(WARM_UP_BLINK);

    // add to ttal time
    totalTime += WARM_UP_BLINK;

  } // while

  // end with LED off
  digitalWrite(LED_BUILTIN, LOW);

  Serial.println("  done");

}

void loop() { }