Servo myservo;
int buttonPin = D0;
int servoPin = A4;
int initial_position = 180;
int final_position = 120;
int buttonState;
void setup()
{
Serial.begin(9600);
// Setup pins
pinMode(buttonPin, INPUT_PULLUP);
pinMode(servoPin, OUTPUT);
// Setup Servo to initial position
myservo.attach(servoPin);
myservo.write(initial_position); // Initial
delay(500);
myservo.detach();
}
void loop()
{
// Read button
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
Particle.publish("tag_dispensed", "HIGH");
myservo.attach(servoPin);
myservo.write(final_position);
delay(5000);
myservo.write(initial_position);
Particle.publish("tag_dispensed", "LOW");
// Do something
}
}
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. .