Hello to everyone,
I'm a master student in Interaction design and I'm a beginner in Arduino field, but I really want to improve my knowledge in it as much as possible... And I need of you!
I'm developing a simple project with an LCD screen (16x2) connected to a push button, where I can send a message to the display typing on the serial monitor and the message is displayed for 10 sec after that the button has been pressed. After these 10 seconds, the display turns itself off automatically and I can send a new message to display on it and so on!
This is the code that I'm using to display text on the LCD through the Arduino sketch (it works):
#include <LiquidCrystal.h>
#define LCD_LIGHT_PIN A4
const int buttonPin = 8;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonState = 0;
void setup() {
// Setup the number of columns and rows:
lcd.begin(16, 2);
lcd.noDisplay();
// Set the button pin as an input:
pinMode(buttonPin, INPUT);
// Set the LCD display backlight pin as an output:
pinMode(LCD_LIGHT_PIN, OUTPUT);
// Turn off the LCD backlight:
digitalWrite(LCD_LIGHT_PIN, LOW);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
// Print some text to the LCD:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hello");
lcd.setCursor(0, 0);
lcd.print("world");
// Turn the backlight on:
digitalWrite(LCD_LIGHT_PIN, HIGH);
// Display the text on the LCD.
lcd.display();
// Wait for 10 seconds and then turn off the display and backlight.
delay(10000);
lcd.noDisplay();
digitalWrite(LCD_LIGHT_PIN, LOW);
}
}
This is the modified code that I'm trying to use to send message through the serial monitor but it doesn't works:
#include <LiquidCrystal.h>
#define LCD_LIGHT_PIN A4
const int buttonPin = 8;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonState = 0;
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.noDisplay();
pinMode(buttonPin, INPUT);
pinMode(LCD_LIGHT_PIN, OUTPUT);
digitalWrite(LCD_LIGHT_PIN, LOW);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
digitalWrite(LCD_LIGHT_PIN, HIGH);
lcd.display();
delay(10000);
lcd.noDisplay();
digitalWrite(LCD_LIGHT_PIN, LOW);
}
}
}
}
}
Now, my question is: how can I write properly the modified code? I need to use the serial monitor to send the message on the screen and not to type what I want to read on the arduino sketch.
Hoping to have been clear,
thanks in advance
Edoardo