int photoCellPin = A0;
int bendPin = A1;
int buzzerPin = D3;
int photoCellReading = 0;
int bendReading = 0;
int ledPin = D2;
int ledBrightness = 0;
void setup() {
pinMode(bendPin, INPUT);
pinMode(photoCellPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Particle.variable("light", &photoCellReading, INT);
Particle.variable("bend", &bendReading, INT);
}
void loop() {
photoCellReading = analogRead(photoCellPin);
bendReading = analogRead(bendPin);
ledBrightness = map(photoCellReading, 2800, 4095, 0, 255);
if(bendReading < 250 && ledBrightness < 100){
tone(buzzerPin, 1000, 500);
delay(500);
}else{
if(bendReading < 250){
analogWrite(ledPin, 255);
delay(1500);
analogWrite(ledPin, 0);
delay(500);
}else{
if(ledBrightness < 100){
analogWrite(ledPin, 255);
delay(500);
analogWrite(ledPin, 0);
delay(1500);
}
}
}
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. .