Trouble with SPDT on/on toggle switch to change message on I2C LCD module

Hello.
I’m fairly new to Arduino and not very good with electronics.

I currently purchased a 16x2 LCD display with an I2C module. I have 2 SPDT on/on toggle switches and I’ve been trying to use them to show different messages when any of the switch is toggled. I tried it with only one switch to see if things can get going, but for some reason, it didnt. I’ve tried several ways to amke this work but none of them seem to work. All I get is either a flickering message, or only one message even though I toggle.

I connected the middle pin of the switch to the 3.3v output of the arduino through a 1k OHM resistor and the other two pins to 12 and 13. I connected the Vcc of I2C to the 5v out, Gnd to Gnd, SDA to A4 and SCL TO A5. i tried writing different types of codes, some of them are as below:

#include<LiquidCrystal_I2C>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int switchState1=0;
int switchState2=0;
void setup()
{
pinMode(12, INPUT);
pinMode(13, INPUT);
lcd.init();
lcd.backlight();
}
void loop()
{
switchState1=digitalRead(13);
switchState2=digitalRead(12);
if(switchState1==LOW) //also tried doing (switchState1==LOW && switchState2==HIGH) in both if/else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("First mode");
}
else if(switchState2==LOW)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Second mode");
}
}

Also tried this way:

#include<LiquidCrystal_I2C>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int switchState1=0;
int switchState2=0;
int current=0;
int previous=0;
void setup()
{
pinMode(12, INPUT);
pinMode(13, INPUT);
lcd.init();
lcd.backlight();
}
void loop()
{
switchState1=digitalRead(13);
current=digitalRead(13);
switchState2=digitalRead(12);
if(current!=previous)
{
if(switchState1==LOW) 
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("First mode");
}
else if(switchState2==LOW)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Second mode");
}
}
previous =current;
}

Tried several other ways too but none seem to work.
Can someone please show me how to change messages on I2C LCD module by toggling an SPDT on/on toggle switch?

Use INPUT_PULLUP with pinMode()

Make buttons or switches make to GND.

If you want to use a button to "toggle" a state you need to debounce it. i.e. read multiple times, only valid when you get steady value for 50ms or so.

David.

p.s. please press ctrl-T to format your code before pasting.

Why on earth would you connect something to the 3.3 V pin?