Hardware components | ||||||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
|
#include <Servo.h>
/*0-lock position,170-open position*/
Servo lock;
void setup()
{
lock.attach(2);
Serial.begin(9600);
lock.write(0);
delay(500);
}
void loop()
{
int i;
int s=1;
start:
int a;
if(Serial.available()>0)
{
a=Serial.read();
if(a==9&&(s==1))
{
for(i=0;i<=170;i++)
{
lock.write(i);
delay(7);
}
Serial.print("OPEN");
s=0;
}
if((s==0)&&(a==5))
{
for(i=170;i>=0;i--)
{
lock.write(i);
delay(7);
}
Serial.print("LOCKED");
s=1;
}
}
goto start;
}
Comments
Please log in or sign up to comment.