Is it possible to use pin 13 for both the built-in LED and as SPI clock pin?

Hi everyone.

I'm trying to make a small sensor logger using an Arduino Nano, logging to a micro SD card using SPI. I also want to use the on-board LED to indicate various things (e.g. blinking rapidly = logging data, blinking slowly = idle, etc.).

Will writing to pin 13 using digitalWrite() interfere with the functioning of the SD card logger, with which I communicate using SPI? I'd like to not have to add an external LED to this little thing I'm building.

Thanks for any input!

Try modifying the Blink sketch to add SPI.begin:

#include <SPI.h>

int led = 13;

void setup() 
{   
  SPI.begin ();  
  pinMode(led, OUTPUT);     
}

void loop() 
  {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  }

The LED does not blink, so the answer is no, you can't use it for both purposes.

You could conceivably turn SPI off if you needed to blink the LED, and turn it back on afterwards:

#include <SPI.h>

int led = 13;

void setup() 
{   
  SPI.begin ();  
  pinMode(led, OUTPUT);     
}

void loop() 
  {
  SPI.end ();    // turn SPI off for a moment
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  SPI.begin ();// turn SPI back on
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  }

But I would do that with a certain amount of caution, if you had open files on the SD card.

Thanks - yeah, turning SPI on and off seems clunky, and with the delays required for blinking it would probably slow the whole thing down a lot. Looks like I'm adding an LED to this thing.