Back to Parent

// Include Particle Device OS APIs
#include "Particle.h"

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);

//sensor
int bendPin = A0;
int bendReading = 0;
int threshold_1 = 500;

int pressPin = A1;
int pressReading = 0;
int threshold_2 = 500;

//output
int ledPin = D1;
int ledBrightness = 0;

//int piezonPin = D3;
//int piezonReading = 0;


void setup() {
  pinMode(ledPin, OUTPUT);
  //pinMode(piezonPin, OUTPUT);
  Particle.variable("bend", &bendReading, INT);
  Particle.variable("Press",&pressReading, INT);
}


void loop() {

  pressReading = analogRead(pressPin);
  bendReading = analogRead(bendPin);
  
  if(bendReading<threshold_1 && pressReading<threshold_2){
      //noTone(piezonPin);
      digitalWrite(ledPin, LOW);
  }
  else if(bendReading>threshold_1 && pressReading>threshold_2){
      //tone(piezonPin, 1000);
      digitalWrite(ledPin,HIGH);
      delay(1500);
      digitalWrite(ledPin,LOW);
      delay(500);
  }
  else if(pressReading>threshold_2 && bendReading<threshold_1){
      //tone(piezonPin, 500);
      digitalWrite(ledPin,HIGH);
      delay(1000);
      digitalWrite(ledPin,LOW);
      delay(1500);
  }
  else if(bendReading>threshold_1 && pressReading<threshold_2){
      //tone(piezonPin, 500);
      digitalWrite(ledPin,HIGH);
      delay(500);
      digitalWrite(ledPin,LOW);
      delay(1500);
  }
  else{
      digitalWrite(ledPin,LOW); 
      //noTone(piezonPin);
  }

  delay(500);
 

}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0