//CODE WITH DELAY
int ledPin = D1;
Servo fatFishFeeder;
int buttonPin = D0;
int servoPin = A5;
int servoPos = 5;
void setup()
{
pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
pinMode( ledPin , OUTPUT ); // sets pin as output
fatFishFeeder.attach( A5 );
Particle.function("servo", servoControl);
Particle.variable ("servoPos", &servoPos, INT);
}
void loop()
{
int buttonState = digitalRead( buttonPin );
if( buttonState == LOW )
{
// turn the LED On
digitalWrite( ledPin, HIGH);
fatFishFeeder.write(180);
Particle.publish("Fat_Fish_Fed", "Fed");
delay(2000);
fatFishFeeder.write(5);
delay(60000);
}else{
digitalWrite( ledPin, LOW);
fatFishFeeder.write(5);
}
//delay(1000);
}
int servoControl(String command)
{
// Convert
int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
servoPos = constrain( newPos, 5 , 180);
// Set the servo
fatFishFeeder.write( servoPos );
// done
return 1;
}
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. .