Percobaan1 Push Button dan LED
1. Rangkai semua komponen sesuai kondisi yang dipilih
2. buat program di aplikasi arduino IDE
3. setelah selesai masukkan program ke arduino di proteus
4. jalankan program pada simulasi dan cobakan sesuai dengan modul dan kondisi
5. Selesai
2. Hardware dan diagram blok
[Kembali]
1. Arduino Uno
2. Switch
3. LED
4. Resistor
Diagram Blok :
3. Rangkaian Simulasi dan Prinsip kerja
[Kembali]
→ Gambar Rangkaian Sebelum Disimulasikan
→ Gambar Rangkaian Setelah Disimulasikan
PRINSIP KERJA
saat program dijalankan dan masuk ke komponen arduino. Selanjutnya, program terus berjalan dalam loop utama, menunggu input dari pengguna. jika ada input dari button akan menyebabkan led hidup, terdapat 2 kondisi dan dimana sebelum kondisi ini dilakukan maka semua led akan di-low-kan terlebih dahulu.
kondisi 1 : saat 2 button ditekan secara bersamaan (2 button ini dipilih acak) maka program akan memasuki loop dan arduino akan membaca input dari button tadi dan akan menyebabkan 2 led menyala sesuai dengan keadaan yang ada pada program
kondisi 2 : saat 3 button ditekan secara bersamaan maka program akan memasuki loop dan arduino akan membaca input dari button dan 7 led akan running.
4. FlowChart [Kembali]
int led[] = {2, 3, 4, 5, 6, 7, 8};
#define button1 A0
#define button2 A1
#define button3 A2
#define button4 A3
#define button5 A4
#define button6 A5
#define button7 13
void setup() {
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(button5, INPUT);
pinMode(button6, INPUT);
pinMode(button7, INPUT);
for (int i = 0; i < 6; i++) {
pinMode(led[i], OUTPUT);
}
}
void loop() {
int b1 = digitalRead(button1);
int b2 = digitalRead(button2);
int b3 = digitalRead(button3);
int b4 = digitalRead(button4);
int b5 = digitalRead(button5);
int b6 = digitalRead(button6);
int b7 = digitalRead(button7);
// Matikan semua LED terlebih dahulu
for (int i = 0; i < 6; i++) {
digitalWrite(led[i], LOW);
}
// Hidupkan 3 LED sesuai dengan 3 tombol yang ditekan
if (b1 == HIGH && b2 == HIGH && b3 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[1], HIGH);
digitalWrite(led[2], HIGH);
}
if (b1 == HIGH && b2 == HIGH && b4 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[1], HIGH);
digitalWrite(led[3], HIGH);
}
if (b1 == HIGH && b2 == HIGH && b5 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[1], HIGH);
digitalWrite(led[4], HIGH);
}
if (b1 == HIGH && b2 == HIGH && b6 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[1], HIGH);
digitalWrite(led[5], HIGH);
}
if (b1 == HIGH && b2 == HIGH && b7 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[1], HIGH);
digitalWrite(led[6], HIGH);
}
if (b1 == HIGH && b3 == HIGH && 43 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[3], HIGH);
}
if (b1 == HIGH && b3 == HIGH && b5 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[4], HIGH);
}
if (b1 == HIGH && b3 == HIGH && b6 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[5], HIGH);
}
if (b1 == HIGH && b3 == HIGH && b7 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[6], HIGH);
}
if (b1 == HIGH && b4 == HIGH && b5 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
}
if (b1 == HIGH && b4 == HIGH && b6 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[5], HIGH);
}
if (b1 == HIGH && b4 == HIGH && b7 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[6], HIGH);
}
if (b1 == HIGH && b5 == HIGH && b6 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
}
if (b1 == HIGH && b5 == HIGH && b7 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[6], HIGH);
}
if (b1 == HIGH && b6 == HIGH && b7 == HIGH) {
digitalWrite(led[0], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[7], HIGH);
}
if (b2 == HIGH && b3 == HIGH && b4 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[3], HIGH);
}
if (b2 == HIGH && b3 == HIGH && b5 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[4], HIGH);
}
if (b2 == HIGH && b3 == HIGH && b6 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[5], HIGH);
}
if (b2 == HIGH && b3 == HIGH && b7 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[6], HIGH);
}
if (b2 == HIGH && b4 == HIGH && b5 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
}
if (b2 == HIGH && b4 == HIGH && b6 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[5], HIGH);
}
if (b2 == HIGH && b4 == HIGH && b7 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[6], HIGH);
}
if (b2 == HIGH && b5 == HIGH && b6 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
}
if (b2 == HIGH && b5 == HIGH && b7 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[6], HIGH);
}
if (b2 == HIGH && b6 == HIGH && b7 == HIGH) {
digitalWrite(led[1], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[6], HIGH);
}
if (b3 == HIGH && b4 == HIGH && b5 == HIGH) {
digitalWrite(led[2], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
}
if (b3 == HIGH && b4 == HIGH && b6 == HIGH) {
digitalWrite(led[2], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[5], HIGH);
}
if (b3 == HIGH && b4 == HIGH && b7 == HIGH) {
digitalWrite(led[2], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[6], HIGH);
}
if (b3 == HIGH && b5 == HIGH && b6 == HIGH) {
digitalWrite(led[2], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
}
if (b3 == HIGH && b6 == HIGH && b7 == HIGH) {
digitalWrite(led[2], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[6], HIGH);
}
if (b4 == HIGH && b5 == HIGH && b6 == HIGH) {
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
}
if (b4 == HIGH && b5 == HIGH && b7 == HIGH) {
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[6], HIGH);
}
if (b4 == HIGH && b6 == HIGH && b7 == HIGH) {
digitalWrite(led[3], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[6], HIGH);
}
if (b5 == HIGH && b6 == HIGH && b7 == HIGH) {
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[6], HIGH);
}
else if (!(b1 == HIGH && b2 == HIGH && b4 == HIGH) &&
!(b1 == HIGH && b2 == HIGH && b3 == HIGH) &&
!(b1 == HIGH && b2 == HIGH && b5 == HIGH) &&
!(b1 == HIGH && b2 == HIGH && b6 == HIGH) &&
!(b1 == HIGH && b2 == HIGH && b7 == HIGH) &&
!(b1 == HIGH && b3 == HIGH && b4 == HIGH) &&
!(b1 == HIGH && b3 == HIGH && b5 == HIGH) &&
!(b1 == HIGH && b3 == HIGH && b6 == HIGH) &&
!(b1 == HIGH && b3 == HIGH && b7 == HIGH) &&
!(b1 == HIGH && b4 == HIGH && b5 == HIGH) &&
!(b1 == HIGH && b4 == HIGH && b6 == HIGH) &&
!(b1 == HIGH && b4 == HIGH && b7 == HIGH) &&
!(b1 == HIGH && b5 == HIGH && b6 == HIGH) &&
!(b1 == HIGH && b5 == HIGH && b7 == HIGH) &&
!(b1 == HIGH && b6 == HIGH && b7 == HIGH) &&
!(b2 == HIGH && b3 == HIGH && b4 == HIGH) &&
!(b2 == HIGH && b3 == HIGH && b5 == HIGH) &&
!(b2 == HIGH && b3 == HIGH && b6 == HIGH) &&
!(b2 == HIGH && b3 == HIGH && b7 == HIGH) &&
!(b2 == HIGH && b4 == HIGH && b5 == HIGH) &&
!(b2 == HIGH && b4 == HIGH && b6 == HIGH) &&
!(b2 == HIGH && b4 == HIGH && b7 == HIGH) &&
!(b2 == HIGH && b5 == HIGH && b6 == HIGH) &&
!(b2 == HIGH && b5 == HIGH && b7 == HIGH) &&
!(b2 == HIGH && b6 == HIGH && b7 == HIGH) &&
!(b3 == HIGH && b4 == HIGH && b5 == HIGH) &&
!(b3 == HIGH && b4 == HIGH && b6 == HIGH) &&
!(b3 == HIGH && b4 == HIGH && b7 == HIGH) &&
!(b3 == HIGH && b5 == HIGH && b6 == HIGH) &&
!(b3 == HIGH && b6 == HIGH && b7 == HIGH) &&
!(b4 == HIGH && b5 == HIGH && b6 == HIGH) &&
!(b4 == HIGH && b5 == HIGH && b7 == HIGH) &&
!(b4 == HIGH && b6 == HIGH && b7 == HIGH) &&
!(b5 == HIGH && b6 == HIGH && b7 == HIGH)) {
// Hidupkan 7 LED running sesuai dengan 2 tombol yang ditekan
if (b1 == HIGH && b2 == HIGH ||
b1 == HIGH && b3 == HIGH ||
b1 == HIGH && b4 == HIGH ||
b1 == HIGH && b5 == HIGH ||
b1 == HIGH && b6 == HIGH ||
b1 == HIGH && b7 == HIGH ||
b2 == HIGH && b3 == HIGH ||
b2 == HIGH && b4 == HIGH ||
b2 == HIGH && b5 == HIGH ||
b2 == HIGH && b6 == HIGH ||
b2 == HIGH && b7 == HIGH ||
b3 == HIGH && b4 == HIGH ||
b3 == HIGH && b5 == HIGH ||
b3 == HIGH && b6 == HIGH ||
b3 == HIGH && b7 == HIGH ||
b4 == HIGH && b5 == HIGH ||
b4 == HIGH && b6 == HIGH ||
b4 == HIGH && b7 == HIGH ||
b5 == HIGH && b6 == HIGH ||
b5 == HIGH && b7 == HIGH ||
b6 == HIGH && b7 == HIGH ) {
for (int i = 0; i < 7; i++) {
digitalWrite(led[i], HIGH);
delay(100);
digitalWrite(led[i], LOW);
}
}
}
}
b. Flowchart
5. Kondisi [Kembali]Kondisi : Percobaan 1 Kondisi 6
3 button menghidupkan 3 LED, 2 button menghidupkan 7 LED running
6. Video Simulasi [Kembali]
7. Download File
[Kembali]
Download Simulasi Rangkaian Klik disini
Download HTML Klik disini
Download Video Simulasi Klik disini
Download Datasheet ARDUINO UNO klik disini
Tidak ada komentar:
Posting Komentar