int ledPin = D2;
int buttonPin = D3;
int forcePin = A2;
int buttonState = 0;
int forceReading = 0;
int sos = 0;
void setup() {
// Configure the pins to be outputs
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Particle.variable("button", buttonState);
Particle.variable("Force-Sensitive Resistor", forceReading);
Particle.variable("sos", sos);
}
void flash(String s) {
if (s == "S") {
Particle.publish("S...");
for (int i = 0; i < 3; i++) {
// Particle.publish(char(i));
digitalWrite( ledPin, HIGH);
delay(1000);
digitalWrite( ledPin, LOW);
delay(1000);
}
}
if (s == "O") {
Particle.publish("O...");
for (int i = 0; i < 3; i++) {
digitalWrite( ledPin, HIGH);
delay(3000);
digitalWrite( ledPin, LOW);
delay(1000);
}
}
}
void SOS() {
flash("S");
delay(3000);
flash("O");
delay(3000);
flash("S");
}
void loop() {
buttonState = digitalRead( buttonPin);
forceReading = analogRead( forcePin);
if (buttonState == LOW) {
if (forceReading > 1000) {
sos = 1;
SOS();
Particle.publish("SOS...");
} else {
sos = 0;
}
}
delay(500);
}
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. .