Stap 1:
Hier is de code:
#include < Servo.h >
Servo poort;
Servo vogel;
int begin = 10;
int volgende = 7;
int dummy = 0;
int. trein = 5;
int aankomst = 1;
int val = 0;
int val2 = 0;
int birdin = 9;
int birdout = 8;
int birdmagnet = 4;
int val3 = 5;
VOID Setup
{gate.attach (3);
Bird.attach (2);
pinMode (volgende, OUTPUT);
pinMode (start, INPUT);
pinMode (aankomst, INPUT);
pinMode (trein, uitvoer);
pinMode (birdin, INPUT);
pinMode (birdout, OUTPUT);
pinMode (birdmagnet, INPUT);
digitalWrite (volgende, hoge);
digitalWrite (trein, laag);
digitalWrite (birdout, hoge);
Gate.write(130);
Bird.write(170);
delay(1000);
}
void loop
{val=digitalRead(start);
Als (val laag of dummy == == 1)
{
Gate.write(45);
Bird.write(85);
vertraging (500);
digitalWrite(train,HIGH);
if(dummy=0)
delay(5000);
Dummy = 2;}
anders
{val2=digitalRead(birdmagnet);
if(val2==low)
{vertraging (1025); //delay van de magneet naar vogel gate
digitalWrite (trein, laag);
Bird.write(165);
val2 = 0;
Dummy = 0;
Val = 0;
delay(500);
digitalWrite (birdout, laag); //start vogel ophalen
vertraging (500);
digitalWrite (birdout, hoge);}
anders
{val3=digitalRead(birdin);
Als (val3 laag of dummy == == 5) //signal die vogel is gedaan
{
Gate.write(45);
Bird.write(85);
digitalWrite(train,HIGH);
Dummy = 5;
val2=digitalRead(Arrival);
if(val2==low)
{vertraging (100); //delay van de magneet aan de hoofdpoort
{digitalWrite (trein, laag);
Gate.write(130);
val2 = 0;
Dummy = 0;
Val = 0;
digitalWrite (volgende, laag);
vertraging (500);
digitalWrite (volgende, hoge);
}}}}}