Pages: [1]   Go Down
Author Topic: How to know if a led is turn on  (Read 291 times)
0 Members and 1 Guest are viewing this topic.
Honduras
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 119
Posts: 4591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (digitalRead(LED)==HIGH) {
  digitalWrite(LED, LOW);   
}
Logged

No, I don't answer questions sent in private messages...

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31543
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Honduras
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot.
Logged

Pages: [1]   Go Up
Jump to: