#include <Servo.h>
Servo rogatki;
#define servo_pin 2
#define P1 3
bool x;
int op;
int currentPos = 0;
int targetPos = 120;
unsigned long lastMove = 0;
const unsigned long stepTime = 30; // ms
const int step = 1;
void setup()
{
Serial.begin(9600);
pinMode(P1, INPUT_PULLUP);
digitalWrite(P1,1);
pinMode(servo_pin, OUTPUT);
rogatki.attach(servo_pin);
x=1;
op=millis();
//rogatki.write(90);
//serwo(90);
//delay(2000);
}
void loop()
{
serwo(270);
/*
if((digitalRead(P1)==0)&&(x==1)&&(millis()-op>=500))
{
x=0;
rogatki.write(0);
op=millis();
}
if(rogatki.read()==0)
{
x=1;
//Serial.print(rogatki.read());
//rogatki.write(90);
//op=millis();
}
*/
}
void serwo(int x)
{
if (millis() - lastMove >= stepTime)
{
lastMove = millis();
if (x < targetPos) x += step;
else if (x > targetPos) x -= step;
currentPos=x;
rogatki.write(currentPos);
}
}