Netaddict



Sie befinden sich hier: Netaddict.de » blinkenlights » LED als Lichtsensor

LED als Lichtsensor

Arduino-Code:

const int ledPin = 11;
unsigned long time = 0;

void setup() {
  // initialize serial communication
  Serial.begin(9600); 
}

void loop() {
  
  // set pin to output
  pinMode(ledPin, OUTPUT);

  //charge LED  
  digitalWrite(ledPin, HIGH);
  delay(1);
  
  // set pin to input
  pinMode(ledPin,INPUT);
  digitalWrite(ledPin, LOW);
  
  // count time while discharging
  time=millis();
  while(digitalRead(11)==HIGH){
    if (millis()-time > 30){
      break;
    }
  };
  time=millis()-time;
  
  // print value to serial
  Serial.println(time);  
}
 

 
XHTML 1.1 CSS 2 Creative Commons License
Netaddict Version 6.0 - © 1996-2017 by netaddict.de - Kontakt