Go Down

Topic: Switching an Output to opposite to last status (Read 718 times) previous topic - next topic

fiddler

I use the onboard LED on pin 13 as a simple visual monitor, to see that, 1; the program is running and 2; how fast the it get around the loop.

So I have a function like this:

void  HeartBeat(void)     
{
  if (HeartBeatState>0)  {
    digitalWrite(13,HIGH);
    HeartBeatState= 0;
  }
  else{
    digitalWrite(13,LOW);
    HeartBeatState= 1;
  }
  return; 

Is there a way to use XOR on the output ?

I guess my question really is: What is the fastest way of switching an output pin ?

Cheers

K

eried


I use the onboard LED on pin 13 as a simple visual monitor, to see that, 1; the program is running and 2; how fast the it get around the loop.

So I have a function like this:

void  HeartBeat(void)     
{
  if (HeartBeatState>0)  {
    digitalWrite(13,HIGH);
    HeartBeatState= 0;
  }
  else{
    digitalWrite(13,LOW);
    HeartBeatState= 1;
  }
  return; 

Is there a way to use XOR on the output ?

I guess my question really is: What is the fastest way of switching an output pin ?

Cheers

K


I remember time ago someone asking for a DigitalWrite(TOGGLE); but I think it was never added. You can however use something like this:
Code: [Select]
boolean s;
void HeartBeat()
{
   digitalWrite(13,s=!s);
}
My website: http://ried.cl

Grumpy_Mike

You can read outputs, so you could do.
Code: [Select]

digitalWrite(13, !digitalRead(13) );

Udo Klein

Or you could have the hardware invert the pin by writing a 1 into the PIN instead of the PORT register.
Check out my experiments http://blog.blinkenlight.net


PeterH


I guess my question really is: What is the fastest way of switching an output pin ?


How fast is fast enough? I find it hard to believe you're actually going to notice the LED switching frequency if you're calling this code frequently enough for performance to be an issue.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy