Go Down

Topic: How to know if a led is turn on (Read 374 times) previous topic - next topic

DiegoTc

Hi
I know the question sounds simple. But
I want to know if it is possible to know when a led is turn on.

Code: [Select]
int LED=13;
void setup() {
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
}

void loop()
{
digitalWrite(LED, LOW);   
}


In this example I am turning of the LED. But I will like that this line  digitalWrite(LED, LOW);    only takes place when the led is on.

Any ideas?

fungus

Code: [Select]

if (digitalRead(LED)==HIGH) {
  digitalWrite(LED, LOW);   
}
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Grumpy_Mike

Code: [Select]

void loop()
{
if(digitalRead(LED) == 0 ) digitalWrite(LED, HIGH);  else digitalWrite(LED, LOW);    
}


However, this will turn on and off so rapidly it will look like it is on all the time.


Go Up