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 )
KẾT LUẬN
Đồ án thiết kế I giúp chúng em hoàn thiện thêm kĩ năng làm việc nhóm. Giúp
chúng em vận dụng được hết các kĩ năng đã học trên giảng đường để áp dụng vào thực
tế. Đồ án thiết kế I cũng đã giúp chúng em hoàn thiện rất nhiều kĩ năng để chuẩn bị tốt
cho công việc sau này.
Nhờ sự giúp đỡ của thầy Trần Hải Nam, chúng em đã có thể hoàn thành tốt môn
Đồ án thiết kế I trong chương trình học.
Chúng em xin chân thành cảm ơn!
Đồ án thiết kế I
Trang 34
PHỤ LỤC: CODE ĐIỀU KHIỂN
int enablePinR = 8; // Noi chan 1 tren L293D
int motorPinR1 = 9; // Noi chan 2 tren L293D Am
int motorPinR2 = 10; // Noi chan 7 tren L293D Duong
int enablePinL= 19; // Noi chan 9 tren L293D
int motorPinL1 =11 ; // Noi chan 10 tren L293D Am
int motorPinL2 =12; // Noi chan 15 tren L293D Duong
int state = 0;
void setup() {
// Cai dat cac chan dau ra:
pinMode(motorPinR1, OUTPUT);
pinMode(motorPinR2, OUTPUT);
pinMode(enablePinR, OUTPUT);
pinMode(motorPinL1, OUTPUT);
pinMode(motorPinL2, OUTPUT);
pinMode(enablePinL, OUTPUT);
// Cai dat chan enable muc HIGH de Motor chay khi mo:
digitalWrite(enablePinR, HIGH);
digitalWrite(enablePinL, HIGH);
//Khoi tao giao tiep ngoai vi o 9600 bits moi giay:
Serial.begin(9600);
}
Đồ án thiết kế I
Trang 35
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