hello guys,
i hope it's the right section to put this in
i am using an LCD 16x2 on which i want to show values from hall effect sensor on the first line and on the second line i have status of 2 Push button, first button is red LED and on the screen is "T-L:" and second button is blue LED and on the screen is "B-L:"
so when the red LED is on i want to print on the LCD: T-L: ON and when off T-L:OFF
same for the blue LED so the final format is this with the spaces :
T-L: ON B-L:OFF
what is happening is that when i am changing from OFF to ON, and extra O is keeping visible like this :
T-L: OON B-L:ONN
so what i want to know is how to clear the OFF world and write ON please ?
here are my codes including the push button, the LEDs and the virtual Wire codes (you can ignore this part, if no let me know please to remove it):
//Sketch of the Controller of the RC car - Firas Helou
//Version September 6 2015
// include the libraries code for LCD and wireless RF Links :
#include <LiquidCrystal.h>
#include <VirtualWire.h>
const byte Red_LED = 2; //Top LEDs ON/OFF indicator
const byte Blue_LED = 4; //Bottom LEDs ON/OFF indicator
const byte TX_Pin = 3; //TX that sends data from the controller to the car
const byte RX_Pin = 5; //RX that receives data sent from the car
const byte RedLeds_Button = 6; //Push Button that turns the Top red LEDs on
const byte BlueLeds_Button = 7; //Push Button that turns the Bottom blue LEDs on
String TopLed = "";
String BottomLed = "";
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //defining the LCD pins
//controlling transmitter initially 12 - TX
int ArrayController[5];
boolean lastRedLed = LOW;
boolean currentRedLed = HIGH;
boolean RedLedOn = false;
boolean lastBlueLed = LOW;
boolean currentBlueLed = HIGH;
boolean BlueLedOn = false;
byte valRedLedButton = 0;
byte valBlueLedButton = 0;
//controlling receiver - RX
int receivingArray[5];
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print("KM/H:");
/*lcd.setCursor(0, 1);
lcd.print("T-L:");
lcd.print(TopLed);
lcd.setCursor(9, 1);
lcd.print("B-L:");
lcd.print(BottomLed);*/
//Transmitter setup
vw_set_tx_pin(TX_Pin); //RF sending pin
vw_setup(2000); // Bits per sec
vw_set_rx_pin(RX_Pin);
vw_rx_start();
pinMode( RedLeds_Button, INPUT_PULLUP ); //RedLeds Button
pinMode( BlueLeds_Button, INPUT_PULLUP ); //BlueLeds Button
pinMode( Red_LED, OUTPUT ); //Red Led indicator Top LEDs
pinMode( Blue_LED, OUTPUT ); //Blue Led indicator Bottom LEDs
}
//Debouncing function
boolean debounce(boolean last, int button)
{
boolean current = digitalRead(button);
if(last != current)
{
delay(5);
current = digitalRead(button);
}
return current;
}
//Main Loop
void loop()
{
currentRedLed = debounce(lastRedLed, RedLeds_Button);
currentBlueLed = debounce(lastBlueLed, BlueLeds_Button);
if(lastRedLed == HIGH && currentRedLed == LOW){
RedLedOn = !RedLedOn;
valRedLedButton = 1;
}else if(lastRedLed == LOW && currentRedLed == HIGH){
valRedLedButton = 0;
}
lastRedLed = currentRedLed;
digitalWrite(Red_LED, RedLedOn);
lcd.setCursor(0, 1);
lcd.print("T-L:");
if(RedLedOn == HIGH){
TopLed = "ON";
lcd.setCursor(5, 1);
lcd.print(TopLed);
}else if(RedLedOn == LOW){
TopLed = "OFF";
lcd.setCursor(4, 1);
lcd.print(TopLed);
}
//if(TopLed == "ON"){
//lcd.setCursor(5, 1);
//lcd.print(TopLed);
//}else if(TopLed == "OFF"){
// lcd.setCursor(4, 1);
// lcd.print(TopLed);
//}
if(lastBlueLed == HIGH && currentBlueLed == LOW){
BlueLedOn = !BlueLedOn;
valBlueLedButton = 1;
}else if(lastBlueLed == LOW && currentBlueLed == HIGH){
valBlueLedButton = 0;
}
lastBlueLed = currentBlueLed;
digitalWrite(Blue_LED, BlueLedOn);
lcd.setCursor(9, 1);
lcd.print("B-L:");
if(BlueLedOn == HIGH){
BottomLed = "ON";
lcd.setCursor(14, 1);
lcd.print(BottomLed);
}else if(BlueLedOn == LOW){
BottomLed = "OFF";
lcd.setCursor(13, 1);
lcd.print(BottomLed);
}
/* if(BottomLed == "ON"){
lcd.setCursor(14, 1);
lcd.print(BottomLed);
}else if(BottomLed == "OFF"){
lcd.setCursor(13, 1);
lcd.print(BottomLed);
}*/
ArrayController[0] = valRedLedButton;
ArrayController[1] = valBlueLedButton;
vw_send((uint8_t*) & ArrayController, sizeof(ArrayController));
vw_wait_tx();
}// --- end of main Loop