Blink and LED while WiFi not Connected

Hi Guys,

I have a nice working project and I'm looking to add a little flash to my visual feedback. While the Arduino (WiFi Shield) is connecting to the network via the while loop,

while (status != WL_CONNECTED)...

I want to have an LED blink. Once it's connected, I want the LED to go solid. Right now, I just have the LED turn on once it's connected. How can I blink an LED during this connection process? Is it possible? Do I have to implement an interrupt? That's new territory for me.

Thanks in advance

Take a look at the blink without delay example and add that into your while loop.

Thank you for your reply. After reading the blink without delay page, I'm not sure that will apply here because the code waits for a connection before it does anything.

// Attempt to connect to WiFi network.
  while (status != WL_CONNECTED) {
    Serial.println("WiFi Shield Online");
    Serial.println();
    Serial.print("Connecting to ");
    Serial.print(ssid);
    Serial.println(" Network ...");
    //status = WiFi.begin(ssid, keyIndex, key);  // WEP
    status = WiFi.begin(ssid, key);  // WPA/WPA2
    
    // Blink networkPin until connection is established.
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;
      if (ledState == LOW) {
        ledState = HIGH;
      } else {
        ledState = LOW;
      }
      digitalWrite(networkPin, ledState);
    }
    
    //tenCountDot();
    //delay(10000);  // Wait 10 seconds for WiFi to connect.
  }

I tried putting the blink code both in before and after the status = WiFi.begin() statement. No difference. What am I missing?

Post all your code? What is interval?

If WiFi.begin() is blocking, then you either need to use a timer interrupt, or rewrite the WiFi.begin() code.

@Nick: My code is over 400 lines and on several tabs. The interval is 1000 as in the blink without delay example.

@Aarch: I figured it would end up an interrupt situation. Not afraid of them just not familiar with them. As far as rewriting the WiFi.begin() function, I haven't thought about it as it's the original library released with 1.0.3.

Any ideas how to blink the LED in the background until the WiFi.begin() function completes?

Thanks in advance for all your help.

PS: Shameless plug: MUSHClient rocks!! :smiley:

Check out the TimerOne library; It's pretty simple to use.

This works for me

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>

boolean status = false;
boolean ledState = true;
int ledPin = 8;
int interval = 1000;
long previousMillis = 0;
long currentMillis;

void setup() 
{
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
  while (status != WL_CONNECTED)
  {
    status = WiFi.begin("foo","bar");
    currentMillis = millis();
    if (currentMillis - previousMillis > interval) 
    {
      previousMillis = currentMillis;
      ledState = !ledState; 
      digitalWrite(ledPin, ledState);    
    }
  }
}

void loop(){}

NOTE 1
I do not actually have a WiFi shield so all bets may be off

NOTE 2
The WiFi library appears to stop some pins acting as digital outputs, notably pin 13, but it may affect others.

Oh, aye.

That's nothing. You can zip them up and make an attachment.

How to use this forum