So im currently trying to display any serial data to an lcd but also have it so if you send a * over serial to the arduino it clears the screen, currently whenever i send something other then a * it shows a random character on the screen other then what i sent, then when i send a * it clears the screen as expected. Any help would be appreciated!
P.S. I have no line ending selected in the arduino serial just for testing to ensure it dosent send anything extra other then what I want it to send.
//libraries im using
#include <LCD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//lcd pin assignments
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
//set lcd pins
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
//data
char data[16];
void setup() {
// begin serial
Serial.begin(9600);
//start lcd
lcd.begin (16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();
}
void loop() {
handleSerial();
if(Serial.available() )
{
lcd.print (data);
}
}
void handleSerial() {
while (Serial.available() > 0) {
char data = Serial.read();
switch (data) {
case '*':
lcd.clear();
break;
}
}
}