int LDR1Pin = D4;
int ledPin = D3;
int LDR2Pin = D2;
int led2Pin = D5;
int LDR1State = 0;
int LDR2State = 0;
void setup() {
Spark.variable("CokeLevel", &LDR1State, INT);
pinMode(ledPin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(LDR1Pin, INPUT);
pinMode(LDR2Pin, INPUT);
}
void loop(){
LDR1State = digitalRead(LDR1Pin);
LDR2State = digitalRead(LDR2Pin);
if(LDR1State == LOW && LDR2State == LOW ) {
digitalWrite(ledPin, HIGH);
digitalWrite(led2Pin, HIGH);
}
else if(LDR1State == HIGH && LDR2State == LOW){
digitalWrite(ledPin, HIGH);
digitalWrite(led2Pin, LOW);
}
else if (LDR1State == HIGH && LDR2State == HIGH){
digitalWrite(ledPin, LOW);
digitalWrite(led2Pin, LOW);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .