int photoCellPin = A0;
int photoCellReading = 0;
int forcePin = A1;
int forceReading = 0;
int ledPin = D2;
int ledBrightness = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
// Create a cloud variable of type integer called 'light' mapped to photoCellReading
Particle.variable("light", &photoCellReading, INT);
Particle.variable("force", &forceReading, INT);
}
void loop()
{
// This gives us a value from 0 to 4095
photoCellReading = analogRead(photoCellPin);
forceReading = analogRead(forcePin);
if (forceReading > 2000 && photoCellReading < 2000) {
blink(1, 2000);
}
else if (forceReading > 2000 && photoCellReading > 2000) {
blink(3, 500);
}
else if (forceReading < 2000 && photoCellReading < 2000) {
blink(5, 200);
}
else {
ledBrightness = 0;
}
// wait 1/10th of a second and then loop
delay(100);
}
void blink(int times, int del) {
for (int i=0; i < times; i++) {
analogWrite(ledPin, 255);
delay(del);
analogWrite(ledPin, 0);
delay(del);
}
}
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. .