งานปฏิบัติ 6
งานปฏิบัติ 6
กดสวิตกลับทางมอเตอร์ แสดงจอ LCD
*Code*
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int mo1 = 1;
int mo2 = 0;
int button1 = 7;
int button2 = 6;
int BS1 = 6;
int BS2 = 7;
void setup() {
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
pinMode(13, OUTPUT);
pinMode(7, INPUT);
pinMode(6, INPUT);
lcd.begin(16, 2);
}
void loop() {
BS1 = digitalRead(6);
BS2 = digitalRead(7);
if (BS1 == LOW) {
digitalWrite(1, LOW);
digitalWrite(0, HIGH);
delay(10);
lcd.setCursor(7, 1);
lcd.print("RIGHT");
digitalWrite(13, LOW);
}
if (BS2 == LOW) {
digitalWrite(1, HIGH);
digitalWrite(0, LOW);
delay(10);
lcd.setCursor(7, 1);
lcd.print("LEFT");
digitalWrite(13, LOW);
}
if (BS1==HIGH && BS2==HIGH)
{
digitalWrite(13, HIGH);
lcd.setCursor(7, 1);
lcd.print("STOP");
digitalWrite(1, LOW);
digitalWrite(0, LOW);
}
}
*Code*
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int mo1 = 1;
int mo2 = 0;
int button1 = 7;
int button2 = 6;
int BS1 = 6;
int BS2 = 7;
void setup() {
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
pinMode(13, OUTPUT);
pinMode(7, INPUT);
pinMode(6, INPUT);
lcd.begin(16, 2);
}
void loop() {
BS1 = digitalRead(6);
BS2 = digitalRead(7);
if (BS1 == LOW) {
digitalWrite(1, LOW);
digitalWrite(0, HIGH);
delay(10);
lcd.setCursor(7, 1);
lcd.print("RIGHT");
digitalWrite(13, LOW);
}
if (BS2 == LOW) {
digitalWrite(1, HIGH);
digitalWrite(0, LOW);
delay(10);
lcd.setCursor(7, 1);
lcd.print("LEFT");
digitalWrite(13, LOW);
}
if (BS1==HIGH && BS2==HIGH)
{
digitalWrite(13, HIGH);
lcd.setCursor(7, 1);
lcd.print("STOP");
digitalWrite(1, LOW);
digitalWrite(0, LOW);
}
}
ความคิดเห็น
แสดงความคิดเห็น