Fala ai galera, beleza?
To trabalhando num código aqui, e gostaria de saber se eu consigo ler dois files do SD card e fazer conta com eles.
Por exemplo, eu tenho data000.txt e data001.txt e quero fazer algo do tipo sum((file1-file2)ˆ2) e gravar esse valor em um outro arquivo, ou até mesmo em um vetor.
Eu tentei fazer direto, uma vez que obtenho os valores escritos no .txt no programa, mas o problema é que eu teria que armazenar esses valores num vetor, e não da certo porque o vetor é muito grande (2000 valores).
Alguém pode me dar uma luz?
Obrigado.
Tags:
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SD.h>
File myFile;
File myFile2;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// re-open the file for reading:
float sum = 0;
myFile = SD.open("data000.txt");
myFile2 = SD.open("data001.txt");
if (myFile) {
Serial.println("FUNCIONANDO 1");
if (myFile2) {
Serial.println("FUNCIONANDO 2");
// read from the file until there's nothing else in it:
while (myFile.available()) {
while (myFile2.available()) {
sum = sum + (myFile.read()-myFile2.read())*(myFile.read()-myFile2.read());
Serial.println(sum);
}
}
// close the file:
myFile.close();
myFile2.close();
}
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
//Serial.println(sum);
}
void loop()
{
// nothing happens after setup
}
Tentei isso daqui, e acredito que estou no caminho certo.
Mas o codigo le a string como char, e eu acredito que tenha que transformá-la em float para fazer a operação de forma correta, alguma sugestão?
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por