Professional Documents
Culture Documents
Kasus 1
Kasus 1
KASUS 1
Catatan :
2. Alur Program
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
boolean lastbutton=LOW;
boolean currentbutton=LOW;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int input=0;
int buzz=13; // Buzzer Pin
int j=3;
int k=12;
void setup() {
lcd.begin();
lcd.backlight();
lcd.print("BAHAYA");
for(int i=3;i<=12;i++)
pinMode(i,OUTPUT);
pinMode(2,INPUT);
}
boolean debounce(boolean last){ //Function to solve the problem of button debouncing
boolean current=digitalRead(2);
if(last!=current)
{
delay(5);
current=digitalRead(2);
}
return current;
}
void loop() {
for(int i=3;i<=12;i++)
digitalWrite(i,LOW);
currentbutton=debounce(lastbutton);
if(lastbutton==LOW && currentbutton==HIGH)
{
input++;
}
lastbutton=currentbutton;
settone(input);
}
if(input==1)
four();
}
void four() { //This function produces the 4th siren(POLICE) sound with led transition.
for(int i=3;i<=11;i+=2)
digitalWrite(i,HIGH);
for(int hz = 440; hz < 1000; hz++){
tone(buzz, hz, 50);
delay(5);
}
for(int i=3;i<=11;i+=2)
digitalWrite(i,LOW);
for(int i=4;i<=12;i+=2)
digitalWrite(i,HIGH);
for(int hz = 1000; hz > 440; hz--){
tone(buzz, hz, 50);
delay(5);
}
}
3. Keterangan Penggunaan
int input=0;
int buzz=13; // Buzzer Pin
int j=3;
int k=12;
Untuk inisialisasi Speaker dan LED
lcd.begin();
lcd.backlight();
lcd.print("BAHAYA");
Untuk Memuncul kan Tulisan di LCD
for(int i=3;i<=12;i++)
pinMode(i,OUTPUT);
pinMode(2,INPUT);
Untuk menyalakan lampu secara bergantian
for(int i=3;i<=11;i+=2)
digitalWrite(i,HIGH);
for(int hz = 440; hz < 1000; hz++){
tone(buzz, hz, 50);
delay(5);
}
for(int i=3;i<=11;i+=2)
digitalWrite(i,LOW);
for(int i=4;i<=12;i+=2)
digitalWrite(i,HIGH);
for(int hz = 1000; hz > 440; hz--){
tone(buzz, hz, 50);
delay(5);
Untuk penyettingan suara sirine polisi
4. Pembuatan Rangkaian
LED 1 = port 3
LED 2 = port 4
LED 3 = port 5
LED 4 = port 6
LED 5 = port 7
Speaker = port 13
I2C LCD
- GND = port GND
- VCC = port 5v
- SDA = A4
- SCL = A5