Hallo zusammen,
ich bekomme es einfach nicht gebacken, zu prüfen, ob ein 4-stelliger Code als txt auf der SD existiert.
Code kommt nur vom Keypad und steht nicht im Programm
Code: 4711
Datei: 4711.txt
customKey = customKeypad.getKey();
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[data_count] = customKey; // store char into data array
lcd.setCursor(data_count,1); // move cursor to show each new char
lcd.print(Data[data_count]); // print char at said cursor
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Password is ");
if(!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
lcd.print("Good");
else
lcd.print("Bad");
delay(1000);// added 1 second delay to make sure the password is completely shown on screen before it gets cleared.
lcd.clear();
clearData();
}
if(! SD.exists(Data)) {...}
geht nicht. Muss es irgendwie als xxx.txt darstellen.
Gesucht und gefunden hab ich Beispiele. Aber ich bringe sie einfach nicht zusammen.
char file[] = "datalog"; //char array? (string) anlegen und mit "datalog" füllen
char endung[] = ".txt"; //char array? (string) anlegen und mit ".txt" füllen
char logfile[12]; //leeres char array? (string) mit platz für 7 + 4 +1mal Null = 12 anlegen
void setup()
{
strcpy(logfile, file); //mit strcpy den Inhalt von "file" in das leere Array "logfile" kopieren
strcacat(logfile, endung); //mit strcat den Inhalt von "endung" an das Array "logfile" anhängen
Serial.println(logfile); // Array "logfile" über SerialMonitor ausgeben
}
oder
void createFilename(char *str, char index1, char index2)
{
sprintf(str,"%c%c.txt",index1,index2);
}
void loop() {
char kombi1[6]={'a','b','c','d','e','f'}; // Eine Auswahl von Buchstaben
char kombi2[6]={'1','2','3','4','5','6'}; // Eine Auswahl von Ziffern
char c1=kombi1[random(0,6)]; // Wähle einen Zufallsbuchstaben aus kombi1
char c2=kombi2[random(0,6)]; // Wähle eine Zufallsziffer aus kombi2
char filename[13]; // Definiere Pufferspeicher für den Dateinamen
createFilename(filename, c1, c2); // Funktionsaufruf zum Bilden des Dateinamens
Serial.println(filename); // Den gebildeten Dateinamen ausgeben
}
und zu guter letzt
//Set FileName 8 chars + "." + 3 more extension chars
while (Serial.available() == 0){
}
if (Serial.available() > 0){
Char Data = Serial.read();
temp += Data; String temp = temp+Data
}
//Then after building the filename, I did this:
temp.toCharArray(FileName, temp.length());
MyFile = SD.open(FileName, FILE_WRITE);
Then writing data, I did this:
MyFile.print(Data);
Wie ganz oben beschrieben, Variablen sind echt nicht mein Ding.
Da schreib ich 1000 mal lieber einen endlichen Automaten.
Ich hoffe ihr helft mir auf die Sprünge
Gruß
Christian