#include <LiquidCrystal_I2C.h>
liquidCrystal_I2C lcd(0x27,20,4);
//Name ADC Channel
int Pot1;
float Pot1_volt;
// Name LED Channel
int LED1 = 21;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, Muhamad Budi Setiawan");
pinMode(LED1, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Pot1 = analogRead(34);
Pot1_volt = (float) Pot1 * 5.0 / 4095 ; // use 10 bit & Vref 5 Volt
Serial.print("nilai ADC: ");
Serial.print(Pot1);//menunjukan nilai ADC
Serial.print("\t");
Serial.print("nilai ADC Tegangan: ");
Serial.println(Pot1_volt);//show voltage ADC
delay(300); // this speeds up the simulation
alarm(Pot1_volt, LED1, 1000,1000, 500,500, 200,200);
}
void blink(int channel, int on, int off){
digitalWrite(channel, LOW);
delay(on);
digitalWrite(channel, HIGH);
delay(off);
}
void alarm( float ch_adc, int ch_led,int safe_on, int safe_off, int warning_on, int warning_off, int danger_on, int danger_off)
{
if(ch_adc <=2.0){
blink(ch_led, safe_on, safe_off);
}
if(ch_adc <=3.5){
blink(ch_led, warning_on, warning_off);
}
if(ch_adc <=5.0){
blink(ch_led, danger_on, danger_off);
}
}
void loop(){
lcd.init();
lcd.backlight();
lcd.home();
lcd.print("TUGAS MUHAMAD BUDI SETIAWAN");
delay(20);
}