Tugas Pendahuluan 1 Modul 2
(Percobaan 2 Kondisi 4)
1. Rangkai rangkaian di proteus sesuai dengan kondisi percobaan.
2. Tulis program untuk arduino di software Arduino IDE.
3. Compile program tadi, lalu upload ke dalam arduino.
4. Setelah program selesai di upload, jalankan simulasi rangkaian pada proteus.
2. Tulis program untuk arduino di software Arduino IDE.
3. Compile program tadi, lalu upload ke dalam arduino.
4. Setelah program selesai di upload, jalankan simulasi rangkaian pada proteus.
2. Hardware dan Diagram Blok
[Kembali]
3. Rangkaian Simulasi dan Prinsip Kerja
[Kembali]
Rangkaian Simulasi :
Prinsip Kerja :
4. Flowchart dan Listing Program
[Kembali]
Flowchart :
Listing Program :
#include <LiquidCrystal_I2C.h>
#define LED1 13
#define LED2 12
#define LED3 11
#define LED4 10
#define LED5 9
#define LED6 8
#define interruptPin 2
LiquidCrystal_I2C lcd(0x27, 20, 4);
volatile int counter = 0;
volatile bool interruptFlag = false;
void setup() {
lcd.init();
lcd.backlight();
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), resetCounter, FALLING);
}
void loop() {
if (interruptFlag) {
// Jika interrupt terjadi, reset counter dan nyalakan semua LED
counter = 0;
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
delay(3000); // Tahan LED menyala selama 3 detik
interruptFlag = false;
} else {
// Putar motor ke kanan (tambahkan kode sesuai dengan metode Anda)
// Tampilkan counter di LCD
displayCounter(counter);
// Nyalakan LED sesuai kondisi
if (counter % 6 == 0) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (counter % 6 == 1) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (counter % 6 == 2) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (counter % 6 == 3) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (counter % 6 == 4) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, LOW);
} else if (counter % 6 == 5) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, HIGH);
}
// Tunggu 4 detik untuk setiap LED
delay(4000);
// Increment counter
counter++;
// Reset counter ketika mencapai 50
if (counter > 50) {
counter = 0;
}
}
}
void resetCounter() {
interruptFlag = true;
}
void displayCounter(int count) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Counting: ");
lcd.setCursor(9, 0);
lcd.print(count);
}
Percobaan 2 Kondisi 4
Motor ke kanan,LCD menampilkan counting dari 0 sampai 50, setiap counting kelipatan bilangan prima LED running dari led pertama hingga keenam selama 4 detik,ketika diberi interrupt maka counting diulang dari 0 dan led hidup semuanya selama 3 detik
6. Video Simulasi
[Kembali]
7. Download File
[Kembali]
HTML klik disini
File Rangkaian klik disini
Video Percobaan klik disini
Video Percobaan klik disini
Listing Program klik disini
Datasheet Arduino klik disini
Datasheet Button klik disini
0 komentar:
Posting Komentar