Ok, this looks way too big for me to wrap my head around. I can logically see what needs done, but I don't think I can put it together.
I need to be able to list files on the display, and have a user select one of them. They have a 12 digit keypad for user input. It's a 4x20 LCD. The number of files is unknown, but like between 15 - 20 files. So I'm picturing doing it like this on my LCD:
- Filename1
- Filename2
- Filename3
4 More 5 Cancel
Choosing 1-3 will select that file, choosing 4 will then display the next 3 files...
I've read thru all the SD card examples and understand them. And I can tell I will need to use this to access the files:
File entry = dir.openNextFile();
But I'll need my menu to keep looping thru the filenames until the user selects one, and then how will I know which one they selected... I've got a good start on it, take a look at my code. I'm just really stumped on this part. I've got my code commented well, so you can see what I'm doing. The disp. functions for the LCD library, but they're easy to follow. I'm stumped in the selection Select_Part()
Thanks so much for taking time to help.
#include <SPI.h> //for SD card
#include <SD.h> //for SD card
#include <Wire.h> //for I2C LCD/KEYPAD
#include <bv4619_I.h> //for I2C LCD/KEYPAD
//LCD stuff
LCD disp(0x39); // constructor defines pins and the address of the device
//SD card stuff
const int chipSelect = 10; //chip select pin for SD card
const int LEN = 43; //max length of lines on SD card
char line[LEN + 1]; // +1 allows space for the null terminator
int CharCounter = 0; //SD card line character counter
File root;
void setup() {
Serial.begin(9600); // Open serial communications and wait for port to open:
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
disp.lcd_bl(10, 0, 0); //turn on LCD backlight
}
void loop() {
Main_Menu(); //show the main menu
}
void Main_Menu() {
disp.lcd_cls(); // clear display
disp.lcd_rowcol(0, 2); //row, col
disp.lcd_print("DRILL TABLE MENU");
disp.lcd_rowcol(1, 0); //row, col
disp.lcd_print("1. SELECT A PART");
disp.lcd_rowcol(2, 0); //row, col
disp.lcd_print("2. ADD/REMOVE PART");
disp.lcd_rowcol(3, 0); //row, col
disp.lcd_print("3. MANUAL POSITION");
while (1) {
byte k = checkKeyBuffer(); //get a keypress from the user
switch (k) {
case 1:
Select_Part(); //select a part (file name) from a list of all file names
break;
case 2:
Add_Remove(); //show the selected menu
break;
case 3:
Manual_Position(); //show the selected menu
break;
}
}
}
void Select_Part() {
disp.lcd_cls(); //clear display
disp.lcd_print("1. FILENAME 1"); //**NAME OF THE FIRST FILE
disp.lcd_rowcol(1, 0); //row, col
disp.lcd_print("2. FILENAME 2"); //**NAME OF THE 2ND FILE
disp.lcd_rowcol(2, 0); //row, col
disp.lcd_print("3. FILENAME 3"); //**NAME OF THE 3RD FILE
disp.lcd_rowcol(3, 0); //row, col
disp.lcd_print("4. MORE 5. CANCEL"); //4 OR 5 TO SEE MORE FILE NAMES OF CANCEL
}
void Add_Remove() {}
void Manual_Position() {}
int checkKeyBuffer() { //check key buffer every 200 millis
//THIS WILL RETURN THE KEYPRESS
//THE NUMBERS 0 THRU 9; 10 = *; 11 = #; 12 = NO KEY
}