I am making a menu to control different LED's however when the name of each led pops up as you scroll through the menu it needs to clear for the next one, is there a way I can clear every time a button is pushed or anything like this?
#include <LiquidCrystal.h>
const byte buttonPin3 = 10;
const byte buttonPin2 = 7;
const byte buttonPin1 = 6;
const byte ledPin = 13;
const byte ledPin2 = 8;
const byte ledPin3 = 9;
byte buttonPushCounter = 1;
byte buttonState1 = 0;
byte buttonState2 = 0;
byte buttonState3 = 0;
byte Ledstate = 0;
byte Ledstate2 = 0;
byte Ledstate3 = 0;
byte lastButtonState1 = 0;
byte lastButtonState2 = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
lcd.print("LED Menu");
lcd.setCursor(0,1);
}
void loop()
//This part is to set up a count to conrol the basic menu system
{
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 != lastButtonState1)
{
if (buttonState1 == HIGH)
{
buttonPushCounter++;
if(buttonPushCounter > 4)
buttonPushCounter = 1;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else
{
Serial.println("off");
}
}
lastButtonState1 = buttonState1;
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 != lastButtonState2)
{
if (buttonState2 == HIGH)
{
if(buttonPushCounter > 1)
buttonPushCounter--;
else
{
buttonPushCounter = 4;
}
}
}
//This section controlls what the button will do when pressed on the selection option
lastButtonState2 = buttonState2;
buttonState3 = digitalRead(buttonPin3);
Ledstate = digitalRead(ledPin);
if (buttonPushCounter == 1 && buttonState3 == HIGH && Ledstate == LOW)
{
digitalWrite(ledPin, HIGH);
delay (200);
}
buttonState3 = digitalRead(buttonPin3);
Ledstate = digitalRead(ledPin);
if (buttonPushCounter == 1 && buttonState3 == HIGH && Ledstate == HIGH)
{
digitalWrite(ledPin, LOW);
delay (200);
}
buttonState3 = digitalRead(buttonPin3);
Ledstate2 = digitalRead(ledPin2);
if (buttonPushCounter == 2 && buttonState3 == HIGH && Ledstate2 == LOW)
{
digitalWrite(ledPin2, HIGH);
lcd.setCursor(7,1);
lcd.print("LED TWO");
delay (200);
}
buttonState3 = digitalRead(buttonPin3);
Ledstate2 = digitalRead(ledPin2);
if (buttonPushCounter == 2 && buttonState3 == HIGH && Ledstate2 == HIGH)
{
digitalWrite(ledPin2, LOW);
delay (200);
}
buttonState3 = digitalRead(buttonPin3);
Ledstate3 = digitalRead(ledPin3);
if (buttonPushCounter == 3 && buttonState3 == HIGH && Ledstate3 == LOW)
{
digitalWrite(ledPin3, HIGH);
delay (200);
}
buttonState3 = digitalRead(buttonPin3);
Ledstate3 = digitalRead(ledPin3);
if (buttonPushCounter == 3 && buttonState3 == HIGH && Ledstate3 == HIGH)
{
digitalWrite(ledPin3, LOW);
delay (200);
}
// this part is job is to show different this on the screen when scrolling on the menu
if (buttonPushCounter == 1)
{
lcd.setCursor(7,1);
lcd.print("LED ONE");
}
if (buttonPushCounter == 2)
{
lcd.setCursor(7,1);
lcd.print("LED TWO");
}
if (buttonPushCounter == 3)
{
lcd.setCursor(7,1);
lcd.print("LED THREE");
}
if (buttonPushCounter == 4)
{
lcd.setCursor(7,1);
lcd.print("LED FOUR");
}
}
You can write spaces to wipe the line or part of it. Set the cursor one the line and character position print spaces to erase the number of character needed. Reset the cursor back and print your data. This is much faster than doing LCD,clear().
When scrolling through the LED's the screen will come up with LED One, LED Two etc, however I want it the clear the last state of the menu before moving on to the next one,
and if i where to use spacers to over write what was last shown on the screen will i have to use a delay? for example
so I changed the code and now it just keeps flashing between the two
// this part is job is to show different this on the screen when scrolling on the menu
if (buttonPushCounter == 1)
{
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print("LED ONE");
}
if (buttonPushCounter == 2)
{
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print("LED TWO");
}
if (buttonPushCounter == 3)
{
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print("LED THREE");
}
if (buttonPushCounter == 4)
{
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print("LED FOUR");
}
}
In my new bit of code where it deletes the previous shown text before the new one it keeps bouncing back and forth, so I need a way to make it stick to the second park of the code.
// this part is job is to show different this on the screen when scrolling on the menu
if (buttonPushCounter == 1)
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("LED ONE");
}
if (buttonPushCounter == 2)
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("LED TWO");
}
if (buttonPushCounter == 3)
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("LED THREE");
}
if (buttonPushCounter == 4)
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("LED FOUR");
}
so I wrote the code so when the button is pressed and the count changes it will wipe every thing and then read the value and display what it is told, so if you look at the code I posted it will display a bunch of spaces to clear the perviously shown text and then strait after it will show the new text. the problem is when the count is lets say 1 it will first display the spacers then "LEDONE" now I need it to stop on "LEDONE" instead it keeps jumping between the two. I need to know how to hold it on "LEDONE" till the count is changed?
the problem is when the count is lets say 1 it will first display the spacers then "LEDONE" now I need it to stop on "LEDONE" instead it keeps jumping between the two.
You need to deal with your frustration in some other way. Pissing and moaning does not help here. You need to be VERY specific as to what "jumping between the two" means.
If you mean that the spaces show while the cursor is being repositioned, and then the text shows, while loop() iterates and the cursor is repositioned, then the simple solution is to write the spaces only when the value of buttonPushCounter changes.
I'm not annoyed Paul Neither am I moaning just trying to find the best way to describe my problem so I can get the most relevant advice I will try writing the spaces every time the button is pressed for changing the count.