1. Trang chủ >
  2. Kỹ Thuật - Công Nghệ >
  3. Điện - Điện tử >

PHỤ LỤC: CODE ĐIỀU KHIỂN

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (821.18 KB, 40 trang )


void loop() {

//Neu co tin hieu vao, doc va xuat trang thai

if(Serial.available() > 0){

state = Serial.read();

}

// Neu state = s DC Motor se DUNG

if (state == 's') {

digitalWrite(motorPinR1, LOW); // Chan 2 tren L293D muc LOW

digitalWrite(motorPinR2, LOW); // Chan 7 tren L293D muc LOW

digitalWrite(motorPinL1, LOW); // Chan 10 tren L293D muc LOW

digitalWrite(motorPinL2, LOW); // Chan 15 tren L293D muc LOW

Serial.println("Motor: TAT");

state = 0; // De state ve 0 khong anh huong gia tri nhap tiep theo

}

// Neu state = f DC Motor se TIEN

else if (state == 'f') {

digitalWrite(motorPinR1, LOW); // Chan 2 tren L293D muc LOW

digitalWrite(motorPinR2, HIGH); // Chan 7 tren L293D muc HIGH

digitalWrite(motorPinL1, LOW); // Chan 10 tren L293D muc LOW

digitalWrite(motorPinL2, HIGH); // Chan 15 tren L293D muc HIGH

Serial.println("Motor: TIEN");

state = 0; // De state ve 0 khong anh huong gia tri nhap tiep theo

Đồ án thiết kế I



Trang 36



}

//Neu state = b DC Motor se LUI

else if (state == 'b') {

digitalWrite(motorPinR1, HIGH); // Chan 2 tren L293D muc HIGH

digitalWrite(motorPinR2, LOW); // Chan 7 tren L293D muc LOW

digitalWrite(motorPinL1, HIGH); // Chan 10 tren L293D muc LOW

digitalWrite(motorPinL2, LOW); // Chan 15 tren L293D muc LOW

Serial.println("Motor: LUI");

state = 0; // De state ve 0 khong anh huong gia tri nhap tiep theo

}

//Neu state = l DC Motor se RE TRAI

else if (state == 'l') {

digitalWrite(motorPinR1, LOW); // Chan 2 tren L293D muc LOW

digitalWrite(motorPinR2, HIGH); // Chan 7 tren L293D muc HIGH

digitalWrite(motorPinL1, LOW); // Chan 10 tren L293D muc LOW

digitalWrite(motorPinL2, LOW); // Chan 15 tren L293D muc LOW

Serial.println("Motor: RE TRAI");

state = 0; // De state ve 0 khong anh huong gia tri nhap tiep theo

}



//Neu state = r DC Motor se RE PHAI

else if (state == 'r') {

Đồ án thiết kế I



Trang 37



digitalWrite(motorPinR1, LOW); // Chan 2 tren L293D muc LOW

digitalWrite(motorPinR2, LOW); // Chan 7 tren L293D muc LOW

digitalWrite(motorPinL1, LOW); // Chan 10 tren L293D muc LOW

digitalWrite(motorPinL2, HIGH); // Chan 15 tren L293D muc HIGH

Serial.println("Motor: RE PHAI");

state = 0; // De state ve 0 khong anh huong gia tri nhap tiep theo

}

}



Đồ án thiết kế I



Trang 38



Tài liệu tham khảo

[1] http://energia.nu/

[2] http://arduino.vn/



Đồ án thiết kế I



Trang 39



Xem Thêm
Tải bản đầy đủ (.pdf) (40 trang)

×