#include <LiquidCrystal_I2C.h> // Libreria que controla el I2C
#include <Wire.h> // La libreria Wire viene incluida en el IDE de arduino
// LCD screen addresses
LiquidCrystal_I2C primaryLcd(0x20, 16, 2);
LiquidCrystal_I2C secondaryLcd1(0x21, 16, 2);
LiquidCrystal_I2C secondaryLcd2(0x22, 16, 2);
LiquidCrystal_I2C secondaryLcd3(0x23, 16, 2);
LiquidCrystal_I2C secondaryLcd4(0x24, 16, 2);
// LED pins
const int ledPins[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4};
const int speakerPin = 3;
void setup() {
configureOutputPins();
configurePrimaryLcd();
configureMessage(secondaryLcd1, "Buenos dias", " Ingeniero :)");
configureMessage(secondaryLcd2, "Ingenieria", " Informatica");
configureMessage(secondaryLcd3, "Quiero un", " Tamal");
configureMessage(secondaryLcd4, "Si el Don pudo", "El Arduino tamb");
}
void loop() {
digitalWrite(speakerPin, LOW);
turnOnLedsUpToDown();
digitalWrite(speakerPin, HIGH);
turnOnLedsDownToUp();
}
void configureOutputPins() {
for (int i = 0; i < 10; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(speakerPin, OUTPUT);
}
void ledBlinking(int ledPin) {
digitalWrite(ledPin, HIGH);
delay(1500);
digitalWrite(ledPin, LOW);
}
void turnOnLedsUpToDown() {
for (int i = 0; i < 10; i++) {
refreshInfoDisplay(i + 1);
ledBlinking(ledPins[i]);
}
}
void turnOnLedsDownToUp() {
for (int i = 9; i >= 0; i--) {
if (i == 8) {
primaryLcd.setCursor(7, 1);
primaryLcd.print(" ");
}
refreshInfoDisplay(i + 1);
ledBlinking(ledPins[i]);
}
}
void refreshInfoDisplay(int ledNumber) {
primaryLcd.setCursor(7, 1);
primaryLcd.print(ledNumber);
}
void configurePrimaryLcd() {
primaryLcd.init();
primaryLcd.backlight();
primaryLcd.setCursor(7, 0);
primaryLcd.print("PSE");
primaryLcd.setCursor(3, 1);
primaryLcd.print("LED: ON");
}
void configureMessage(LiquidCrystal_I2C lcd, String firstMessage, String secondMessage) {
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(firstMessage);
lcd.setCursor(0, 1);
lcd.print(secondMessage);
}