Mini Project ควบคุมมอเตอร์และไฟ Led.
Mini Project ควบคุมมอเตอร์และไฟ Led.
อุปกรณ์
1.Arduino r3
2.lcd
3.Switch
#include <LiquidCrystal.h>
const int rs = 12, en = 13, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int BS1 = 0;
int BS2 = 0;
int BS3 = 0;
void setup() {
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
lcd.begin(16, 2);
}
void loop() {
BS1 = digitalRead(0);
BS2 = digitalRead(1);
BS3 = digitalRead(2);
if(BS1 == LOW){
digitalWrite(A0,HIGH);
for (int i=0; i <= 355; i++){
digitalWrite(11,HIGH);
delay(8);
digitalWrite(11,LOW);
delay(16);
lcd.setCursor(5,1);
lcd.print(" Speed 5% ");
}
digitalWrite(A1,HIGH);
digitalWrite(A0,LOW);
for (int i=0; i <= 355; i++){
digitalWrite(11,HIGH);
delay(10);
digitalWrite(11,LOW);
delay(10);
lcd.setCursor(5,1);
lcd.print(" Speed 50% ");
}
digitalWrite(A1,LOW);
digitalWrite(A2,HIGH);
for (int i=0; i <= 355; i++){
digitalWrite(11,HIGH);
delay(19);
digitalWrite(11,LOW);
delay(1);
lcd.setCursor(5,1);
lcd.print(" Speed 90% ");
}
}
if(BS2 == LOW){
for (int i=0; i <= 20; i++){
lcd.setCursor(3,1);
lcd.print(" StephLED.1 ");
digitalWrite(7,HIGH);
digitalWrite(A0,HIGH);
delay(100);
digitalWrite(7,LOW);
digitalWrite(A1,LOW);
delay(100);
digitalWrite(8,HIGH);
digitalWrite(A2,HIGH);
delay(100);
digitalWrite(8,LOW);
digitalWrite(A1,LOW);
delay(100);
digitalWrite(9,HIGH);
digitalWrite(A0,HIGH);
delay(100);
digitalWrite(9,LOW);
digitalWrite(A2,LOW);
delay(100);
digitalWrite(10,HIGH);
digitalWrite(A1,HIGH);
delay(100);
digitalWrite(10,LOW);
digitalWrite(A0,LOW);
delay(100);
}
}
if(BS3 == LOW){
for (int i=0; i <= 20; i++){
lcd.setCursor(3,1);
lcd.print(" StephLED.2 ");
digitalWrite(10,HIGH);
digitalWrite(A1,HIGH);
delay(90);
digitalWrite(10,LOW);
digitalWrite(A1,LOW);
delay(90);
digitalWrite(9,HIGH);
digitalWrite(A0,HIGH);
delay(90);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
delay(90);
digitalWrite(8,HIGH);
digitalWrite(A2,HIGH);
delay(90);
digitalWrite(8,LOW);
digitalWrite(A2,LOW);
delay(90);
digitalWrite(7,HIGH);
digitalWrite(A1,HIGH);
delay(90);
digitalWrite(7,LOW);
digitalWrite(A1,LOW);
delay(90);
}
}
else {
digitalWrite(11,LOW);
lcd.setCursor(4,1);
lcd.print(" Welcome...");
}
}
https://youtu.be/QPJOPPAU6vM
ความคิดเห็น
แสดงความคิดเห็น