Back to Parent

Servo myServo;
int servoPin = A3; 
int fsrPin = A0; 
int fsrReading = 0;
int fsrThreshold = 2000; 

void setup() {
  myServo.attach(servoPin);
  pinMode(fsrPin, INPUT);
  myServo.write(55);
    delay(500);
  Serial.begin(9600);
  
  Particle.function("setThreshold", setThreshold); 
  Particle.variable("fsrReading", &fsrReading, INT);
}


void loop() {
  fsrReading = analogRead(fsrPin);
  Serial.println(fsrReading);

  if (fsrReading > fsrThreshold) {
    // Trigger the servo motor
    myServo.write(90); 
    delay(1000); 
    myServo.write(0);
    delay(1000);
     myServo.write(90); 
    delay(1000); 
    myServo.write(0);
    delay(1000); 
  }else{
      myServo.write(25);
  }

  delay(10); 
}

int setThreshold(String command) {
  int newThreshold = command.toInt();
  if (newThreshold > 0) {
    fsrThreshold = newThreshold;
    return 1; 
  } else {
    return -1; 
  }
}
Click to Expand

Content Rating

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

0