Pages: [1]   Go Down
Author Topic: Switching an Output to opposite to last status  (Read 639 times)
0 Members and 1 Guest are viewing this topic.
NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Chile
Offline Offline
Edison Member
*
Karma: 35
Posts: 1251
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
boolean s;
void HeartBeat()
{
   digitalWrite(13,s=!s);
}
Logged

My website: http://ried.cl

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34591
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can read outputs, so you could do.
Code:
digitalWrite(13, !digitalRead(13) );
Logged

0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3496
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Or you could have the hardware invert the pin by writing a 1 into the PIN instead of the PORT register.
Logged

Check out my experiments http://blog.blinkenlight.net

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys, awesome :-)
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: