#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
// buzzer
const int buzzerPin = 13;
// diode
const int diodeinput = A14; // output pin for diode
const int diodeoutput = A10; // input pin for diode
const int diodeled = 42; //diode LED
void setup() {
lcd.init();
lcd.begin(20,4);
lcd.backlight();
lcd.clear();
}
void loop() {
lcd.clear();
diodeTest(); //calling diode testing fucntion
delay(5000);
}
void buzzer(int t) {
tone(buzzerPin, 1000); // play a tone at 440 Hz
delay(t); // wait for 500 milliseconds
noTone(buzzerPin); // stop the tone
}
void diodeTest(){
pinMode( diodeinput, OUTPUT ); //set diode pin modes
pinMode( diodeoutput, INPUT );
lcd.setCursor(0,0);
lcd.print( " Test Result " );
lcd.setCursor(0,1);
lcd.print( "Component: Diode" );
lcd.setCursor(0,2);
lcd.print( "Testing Deiode" );
delay( 1000 );
lcd.setCursor(0,2);
lcd.write(" ");
digitalWrite( diodeinput, HIGH ); //set dioe input pin to high
if( digitalRead( diodeoutput ) == HIGH ){ //check output pin is also high if it is, diode is working
lcd.setCursor(0,2);
lcd.print( "Status: Working" );
buzzer(100);delay(100);buzzer(100); //make two beep
}
else{ //diode is not working
lcd.setCursor(0,2);
lcd.print("Status: Not Working");
buzzer(500); //not working beep
}
digitalWrite( diodeled, LOW);
}