DogBot (6 / 7 stap)

Stap 6: Codering arduino

int legs1 = 3;
int legs2 = 4;
int knees1 = 6;
int knees2 = 7;
int legs3 = 8;
int legs4 = 9;
int knees3 = 10;
int knees4 = 11;
int status;

int vlag = 0;

VOID Setup {}

pinMode (legs1, OUTPUT); been 1 3
pinMode (legs2, OUTPUT); been 13
pinMode (knees1, OUTPUT); knie 1 3
pinMode (knees2, OUTPUT); / / knie 1 3

pinMode (legs3, OUTPUT); / / been 2 4
pinMode (legs4, OUTPUT); / / been 2 4
pinMode(knees3,OUTPUT); / / knie 2 4
pinMode(knees4,OUTPUT); / / knie 2 4

Serial.begin(9600);
}

void loop {}

if(Serial.available() > 0) {}
staat = Serial.read();
vlag = 0;
}

Als (staat == '0') {/ / motor af
digitalWrite (legs1, laag);
digitalWrite (legs2, laag);
digitalWrite(knees1,LOW);
digitalWrite(knees2,LOW);
digitalWrite(legs3,LOW);
digitalWrite(legs4,LOW);
digitalWrite(knees3,LOW);
digitalWrite(knees4,LOW);
if(Flag == 0) {}
Serial.println ("Motor: off");
vlag = 1;
}
}
Indien de staat is '1' zal de motor rechtsaf
anders als (staat == '1') {}
digitalWrite(knees1,HIGH);
digitalWrite(knees2,LOW);
delay(100);
digitalWrite(knees1,LOW);
digitalWrite(knees2,LOW);
delay(400);

digitalWrite (legs1, laag);
digitalWrite (legs2, hoge);
delay(300);
digitalWrite (legs1, laag);
digitalWrite (legs2, laag);
delay(400);

digitalWrite(knees1,LOW);
digitalWrite(knees2,HIGH);
delay(100);
digitalWrite(knees1,LOW);
digitalWrite(knees2,LOW);
delay(400);

digitalWrite (legs1, hoge);
digitalWrite (legs2, laag);
delay(300);
digitalWrite (legs1, laag);
digitalWrite (legs2, laag);
delay(400);

digitalWrite(knees3,HIGH);
digitalWrite(knees4,LOW);
delay(100);
digitalWrite(knees3,LOW);
digitalWrite(knees4,LOW);
delay(400);
digitalWrite(legs3,LOW);
digitalWrite(legs4,HIGH);
delay(300);
digitalWrite(legs3,LOW);
digitalWrite(legs4,LOW);
delay(400);
digitalWrite(knees3,LOW);
digitalWrite(knees4,HIGH);
delay(100);
digitalWrite(knees3,LOW);
digitalWrite(knees4,LOW);
delay(400);
digitalWrite(legs3,HIGH);
digitalWrite(legs4,LOW);
delay(300);
digitalWrite(legs3,LOW);
digitalWrite(legs4,LOW);
delay(400);
if(Flag == 0) {}
Serial.println ("Motor: vooruit");
vlag = 1;
}
}

}

Gerelateerde Artikelen