diff --git a/es/blatt6/uebung6-1/uebung6-1.ino b/es/blatt6/uebung6-1/uebung6-1.ino index 8a1ecf2..923e8c7 100644 --- a/es/blatt6/uebung6-1/uebung6-1.ino +++ b/es/blatt6/uebung6-1/uebung6-1.ino @@ -1,4 +1,5 @@ #include +#include // pins int slaveSelectPin = 10; @@ -304,3 +305,35 @@ int printString(int x, int y, const char* text, int textLength) return 0; } + +/** + * Reads the contents of a text file into a string. + * + * Returns an empty string on failure. + * + * @param File file + */ +const char* readString(File file) +{ + if (file) { + unsigned long fileSize = file.size(); + char result[fileSize]; + int i = 0; + while (file.available()) { + char c = file.read(); + if (c != '\n') { + result[i] = c; + i++; + } + else { + result[i] = '\0'; + } + } + + return result; + } + else { + // something happened + return ""; + } +}