Hi all, I have a problem with my program code. I want to make the relay high and low alternately, but when the conditions are high and low, it displays different text. what is happening now, when the relay is low, it doesn't display text immediately, it has to delay 9000ms first, then text appears, and the text only appears once, and the relay immediately becomes the opposite condition, I want to make a 9000ms delay relay, so that the text appears alternately looping
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
int relay =2;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
delay(2000);
lcd.clear();
pinMode(relay, OUTPUT);
}
void loop()
{
digitalWrite(relay,HIGH);delay(9000);
lcd.setCursor(3,0);
lcd.print("Hello, world!");
delay(3000);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Ywrobot Arduino!");
delay(3000);
lcd.clear();
digitalWrite(relay,LOW);delay(9000);
lcd.setCursor(0,0);
lcd.print("Arduino LCM IIC 2004");
delay(3000);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Power By Ec-yuan!");
delay(3000);
lcd.clear();
}
The microcontroller will run through your code line by line and then, in loop, it will continue to the end then loop back and do it again anon. Try reading your code and translating into English. You can comment it out and include it in the code using //
You should have a good understanding of what each line does and keep in mind the repetition of loop.
is it possible to add text that is displayed alternately during relay high or low? For example, when the relay is high, the RELAY IS HIHG display, displays 1 second, then displays , RELAY IS 1, for 1 second as well, and returns to RELAY IS HIGH, and continues to do so, before the relay returns to a low state.
x
You can mark one answer as solution so anyone can see that this thread is solved.
You can say thank you to people by pressing the heart if you think that their post was helpful for you. Recap your thread and read again the answers - there were several good answers!