Tải bản đầy đủ - 0 (trang)
Code điều khiển theo hướng zíc zắc

Code điều khiển theo hướng zíc zắc

Tải bản đầy đủ - 0trang

void tien(){

for (int x=0;x<=10000;x++){

digitalWrite(12,LOW);

digitalWrite(13,LOW);//dir

digitalWrite(10,HIGH);

delayMicroseconds(100);

digitalWrite(10,LOW);

delayMicroseconds(100);

}

}

void quaphai(){

for(long i=0;i<=175000;i++)

{

//digitalWrite(10,HIGH);

digitalWrite(7,LOW);//enb mo nguon

digitalWrite(8,LOW);//dir chieu dong co

digitalWrite(6,HIGH);//step xung

delayMicroseconds(50);

digitalWrite(6,LOW);//xung

delayMicroseconds(30);

}

}

void quatrai(){

for(long i=0;i<=175000;i++)

{

//digitalWrite(10,HIGH);

digitalWrite(7,LOW);// mo nguon

digitalWrite(8,HIGH);//chieu dong co

digitalWrite(6,HIGH);//xung

delayMicroseconds(50);

digitalWrite(6,LOW);//xung

44



delayMicroseconds(30);

}

}

void xuong(){

for(int a=0;a<=20000;a++)

{

//digitalWrite(7,HIGH);

digitalWrite(9,LOW);//enb

digitalWrite(4,LOW);//dir

digitalWrite(5,HIGH);//xung

delayMicroseconds(150);

digitalWrite(5,LOW);//xung

delayMicroseconds(150);

}

}

void len(){

for(int a=0;a<=20000;a++)

{

//digitalWrite(7,HIGH);

digitalWrite(9,LOW);//enb

digitalWrite(4,HIGH);//dir

digitalWrite(5,HIGH);//xung

delayMicroseconds(150);

digitalWrite(5,LOW);//xung

delayMicroseconds(150);

}

}

void loop() {

len();

tien();

digitalWrite(2,1);

45



for (int n=0;n<=3;n++){

quatrai();

xuong();

quaphai();

xuong();

}

digitalWrite(7,HIGH);

digitalWrite(9,HIGH);

digitalWrite(12,HIGH);

digitalWrite(2,0);

delay(10000);

}

2. Code điều khiển theo hướng hình xoắn ốc

void setup() {

//khai bao chan cua a4988

// 1mm tuong duong 400xung

//20cm= 200mm=80000xung

pinMode(2,OUTPUT);// chân máy phun sơn

//---------dongco1----------trai phai---pinMode(6,OUTPUT);//step

pinMode(7,OUTPUT);//enb

pinMode(8,OUTPUT);//dir

digitalWrite(7,HIGH);

//-----------dongco2---------len xuong---pinMode(5,OUTPUT);//step

pinMode(9,OUTPUT);//enb

pinMode(4,OUTPUT);//dir

digitalWrite(9,HIGH);

//-----------dongco3----------tien lui---pinMode(10,OUTPUT);//step

pinMode(12,OUTPUT);//enb

46



pinMode(13,OUTPUT);//dir

digitalWrite(12,HIGH);

}

void quatrai1(){

//437.5mm

for(long i=0;i<=175000;i++)

{

//digitalWrite(10,HIGH);

digitalWrite(7,LOW);// mo nguon

digitalWrite(8,HIGH);//chieu dong co

digitalWrite(6,HIGH);//xung

delayMicroseconds(50);

digitalWrite(6,LOW);//xung

delayMicroseconds(30);

}

}

void len1(){

//350mm

for(int a=0;a<=140000;a++)

{

//digitalWrite(7,HIGH);

digitalWrite(9,LOW);//enb

digitalWrite(4,HIGH);//dir

digitalWrite(5,HIGH);//xung

delayMicroseconds(150);

digitalWrite(5,LOW);//xung

delayMicroseconds(150);

}

}

void quaphai1(){

//437.5mm

47



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Code điều khiển theo hướng zíc zắc

Tải bản đầy đủ ngay(0 tr)

×