int ledPin = D3;
int phoPin = A5;
int buttonRead = D2;
int phoReading = 0;
int lastButtonState = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonRead, INPUT_PULLUP);
//analog pin always defaults as input
//A cloud variable called photoCellReading and says it is an integer (or number)
Particle.variable("Photocell", &phoReading, INT);
}
void loop() {
int buttonState = digitalRead(buttonRead);
int lastButtonState = LOW;
phoReading = analogRead(phoPin);
// if (buttonState != lastButtonState){
if ((buttonState == LOW) && (phoReading < 1600)){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
if (phoReading >= 1600){
digitalWrite(ledPin, LOW);
}
// }
// lastButtonState == buttonState;
delay(100);
}
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. .