#define potPinLight A1
int potValueLight = 0;
#define potPinTime A2
int potValueTime = 0;
#define ldrPin A0
int ldrValue = 0;
#define ledPin 8
long lightDuration = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(potPinLight, INPUT);
pinMode(potPinTime, INPUT);
pinMode(ldrPin, INPUT);
Serial.begin(9600);
digitalWrite(ledPin, LOW);
}
void loop() {
potValueLight = analogRead(potPinLight);
potValueTime = analogRead(potPinTime);
ldrValue = analogRead(ldrPin);
Serial.print("ldr = "+String(ldrValue));
Serial.print(" pot Light = "+String(potValueLight));
Serial.println(" pot Time = "+String(potValueTime));
if (ldrValue > potValueLight) { // עוצמת האור בחוץ גבוהה מגבול הרגישות ולכן מכבים את הנורה
digitalWrite(ledPin, LOW);
}
else {
lightDuration = potValueTime * 30000L / 1023L;
Serial.print(" Light Duration =");
Serial.println(lightDuration);
digitalWrite(ledPin, HIGH);
delay(lightDuration);
digitalWrite(ledPin, LOW);
}
delay(1000);
}
Comments