Hi
Each time I pressing button the LED is ON and OFF = OK, but LCD is not , the text appears in both lines after 2 pressings and stays that way, should be switching between ("hello 1") and ("hello2").
I tried // lcd.clear(); probably incorrectly.
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
#include <stdio.h>
#include <stdlib.h>
const int button = PB11; // GPIO 8 for the button
const int led = PC13; // GPIO 7 for the LED
int ledflag = 0; // LED status flag
byte z,z0,z1;
int ur,ul,urr,ull;
void setup() {
lcd.begin(16, 2);
pinMode(button, INPUT_PULLDOWN); // define button as an
input
pinMode(led, OUTPUT); // define LED as an output
digitalWrite(led, LOW); // turn output off just in case
}
void loop() {
if (digitalRead(button) == HIGH) { // if button is pressed
if (ledflag == 0) { // and the status flag is LOW
ledflag = 1; // make status flag HIGH
digitalWrite(led, HIGH);
lcd.setCursor(0, 0);
lcd.print("hello 1");// and turn on the LED
//lcd.clear();
} //
else { // otherwise...
ledflag = 0; // make status flag LOW
digitalWrite(led, LOW);
lcd.setCursor(0, 1);
lcd.print("hello2");// and turn off the LED
// lcd.clear();
}
delay(1000); // wait a sec for the
} // hardware to stabilize
// updateDisplay();
} // begin again