I apologize Sir's for the my obsession manner looking for help. I'am just a new bee, starting to code in arduino and just basic knowledge in electronics. I try to follow tutorials on how to use SD card , display i2c Lcd and buttons but i really need guidance on how to accomplish this.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#include <SPI.h>
#include <SD.h>
File myFile;
const int buttonPin1 = 2;
const int buttonPin2 = 3;
int buttonState = 0;
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
lcd.begin(16,2);
lcd.backlight();
myFile = SD.open("test.txt", FILE_WRITE);
}
void loop()
{
lcd.setCursor(0,0); //we start writing from the first row first column
lcd.print(" Press 1 to desplay"); //16 characters poer line
delay(1000);//Delay used to give a dinamic effect
lcd.setCursor(0,1);
lcd.print("Press 2 to delete");
delay(1000);
buttonState = digitalRead(buttonPin1);
if (buttonState == HIGH) {
lcd.print("Initializing SD card...");
myFile = SD.open("test.txt");
if (myFile) {
// how can i display the first line only?
lcd.print("test.txt:");
while (myFile.available()) {
lcd.write(myFile.read());
}
myFile.close();
} else {
lcd.print("error opening test.txt");
}
}
buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH) {
if (myFile) {
//how can i delect the first line of the text.
lcd.print("Initializing SD card...");
delay(1000);
lcd.print("Writing to test.txt...");
myFile.print(" ");
myFile.close();
lcd.print("Deleted");
} else {
lcd.print("error opening test.txt");
}
}
}
SD card text file. test.text
line1: Ranil Abrasado
line2: Bode John
line3: Stephen Biaes
when i press button 1= desplay line1 text from the SD card to the i2c LCD.
and then if i press the button2 = delete the line1 from sdcard text file
Thank You Sir