Не знаю, я по- символам читал, только средствами С, но первое, что выдаёт гугл:
“Для чтения содержимого текстового файла в строку в C++ можно использовать классы ifstream и string из стандартной библиотеки. Сначала нужно открыть файл для чтения, затем создать строку и последовательно добавлять в неё содержимое файла, строка за строкой, используя getline(). В конце файл нужно закрыть.”
Нельзя ардуино считать файл с ПК. Можно на ПК запустить программу, которая будет ждать команду от ардуино на передачу файла, и по этой команде передавать файл. Так же имеет значение способ связи ардуино с ПК.
Знания вовсе не нужны я тупой как пробка.
Ребятки, я раньше через java приложение читал, читал txt файл: передавал из java приложения в arduino путем serial.read переменную. Хочу сделать умный будильник который… бла бла бла тра ля ля…
/*
Serial Event example
When new serial data arrives, this sketch adds it to a String.
When a newline is received, the loop prints the string and clears it.
A good test for this is to try it with a GPS receiver that sends out
NMEA 0183 sentences.
NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or
other ATmega32U4 based boards.
created 9 May 2011
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent
*/
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
routine is run between each time loop() runs, so using delay inside loop can
delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}