Good Day,
I have mod the following code which read from a sdcard to a array, the code read from a input text file "Maxx.txt" to array. everything works fine but there is some data conversion issue.
The binary to decimal conversion is wrong.
The following input text:
04,B11110000,B00001111,B00011100,B11000000
the output is
Initializing SD card...card initialized.
4
4 Fields recieved:
112
87
92
192
but binary to decimal for:
11110000=240, 00001111=15, 00011100=28, 11000000 = 192
THis is the following arduino code
#include <SD.h>
const int chipSelect =10;
int fieldIndex = 0;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
//---------------------------------------------------------------------------
File dataFile = SD.open("Maxx.txt");
if (dataFile)
{
int ch = dataFile.read();
int NoF = 10 * (ch-'0');
ch = dataFile.read();
NoF = NoF + ch-'0';
ch = dataFile.read();
char me = ch;
Serial.println(NoF);
unsigned char values[NoF]; //This is the array to hold the values.
while (dataFile.available())
{
for(fieldIndex = 0; fieldIndex < NoF; fieldIndex ++)
{
values[fieldIndex]=dataFile.parseInt();
}
Serial.print(fieldIndex);
Serial.println(" Fields recieved:");
for(int i = 0; i < fieldIndex; i++)
{
Serial.println(values[i]);
}
fieldIndex = 0;
}
dataFile.close();
}
else
{
Serial.println("error opening Maxx.txt");
}
}
void loop()
{
}
i am newbie to data conversion, so please guide