Back to Parent

int servoPin = D0;
int servoPos = 80;
int buttonPin = A1;

int buttonState = HIGH;
int previousState = HIGH;

Servo myServo;


void setup() {
  myServo.attach(servoPin);
  myServo.write(servoPos);
  pinMode(buttonPin, INPUT_PULLUP);

  Particle.subscribe("DIOTPLAYER2",oppose);
}
void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW && previousState == HIGH) {
    Particle.publish("DIOTPLAYER1","HIGH");
    if (servoPos > 10) {
      servoPos -= 10;
      myServo.write(servoPos);
      //delay(5000);
  }
    else {
      servoPos=80;
      myServo.write(servoPos);
    }
  }

  previousState = buttonState;

}
void oppose(const char *event, const char *data) {
  if (servoPos < 150 ) {
    servoPos += 10;
    myServo.write(servoPos);
  }
  else {
    servoPos=80;
    myServo.write(servoPos);
  }
}
Click to Expand

Content Rating

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

0