Percobaan 1 Kondisi 1
Led & Switch
1. Prosedur [Kembali]
- Rangkai semua komponen
- Buat program di aplikasi arduino IDE
- Setelah selesai masukkan program ke arduino
- Jalankan program pada simulasi dan cobakan sesuai kondisi
- Rangkaian
- Prinsip Kerja
- Flowchart
- Listing Program
#define LED1 2
#define LED2 3
#define LED3 4
#define LED4 5
#define LED5 6
#define LED6 7
#define LED7 8
#define LED8 9
#define PB1 A0
#define PB2 A1
#define PB3 A2
#define PB4 A3
#define PB5 A4
#define PB6 A5
#define PB7 12
#define PB8 13
void setup() {
Serial.begin(9600);
pinMode(PB1, INPUT);
pinMode(PB2, INPUT);
pinMode(PB3, INPUT);
pinMode(PB4, INPUT);
pinMode(PB5, INPUT);
pinMode(PB6, INPUT);
pinMode(PB7, INPUT);
pinMode(PB8, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(LED8, OUTPUT);
}
void loop() {
int b1 = digitalRead(PB1);
int b2 = digitalRead(PB2);
int b3 = digitalRead(PB3);
int b4 = digitalRead(PB4);
int b5 = digitalRead(PB5);
int b6 = digitalRead(PB6);
int b7 = digitalRead(PB7);
int b8 = digitalRead(PB8);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
digitalWrite(LED8, LOW);
int count = b1 + b2 + b3 + b4 + b5 + b6
+ b7 + b8;
if (count == 1) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
}
else if (count == 2) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
delay(500);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
delay(500);
}
else {
// Matikan semua LED jika tidak ada
tombol yang ditekan atau lebih dari 2 tombol yang ditekan
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
digitalWrite(LED8, LOW);
}
}
Video Simulasi klik disini
Listring Program klik disini
Tidak ada komentar:
Posting Komentar