Hi, I am trying to read data from sdcard (raw 0,1), and want to sort it so I can convert it to byte.
This is what I require:
The program, is simple. I have created one file, let say : 'pattern.txt', and save it in the sdcard.(Done)
Then the program will read all the raw data from sdcard, sort it to (8 bits -so I can have a byte), and declare it.
I have to declare it as byte because I will be shifting out this data through the shift register. Hope it's clear.
Let say, here's the raw data from the sdcard (pattern.txt):
00000000000000000000000000011100000000000000000000000000000000000000000000000000
00000000000000000000000000011100000000000000000000000000000000000000000000000000
01110000100001110011111100011100001111110000111111000011111110111110000111111000
01111001110011100111111110011100011111111001111111100011111111111110001111111100
00111001110011101111111110011100011111111001111111110011111111111111001111111110
00111011111011101110000111011100111100111011110001110011100111100111011110001110
as you can see, it's only raw data. So I will be polling the data one by one from the sdcard, and read it.
Here's the program that I test to group it into 8, and print it :
in_char=file.read(); //Get the first byte in the file.
while(in_char >=0){ //If the value of the character is less than 0 we've reached the end of the file.
for(int y=0; y<8; y++){
Serial.print(in_char); //Print the current character
in_char=file.read(); //Get the next character
}
delay(20); // some delay
As you can see, I only read it one by one. My questions :
- After I read the data (every 8 bits), how can I save it to variable, and declare it as a byte? Then read the next bit and do the same thing. (It required only temporary variable, as I will be shifting it out to the shift register right away).
- How can I eliminate(remove or maybe neglect) any spaces in the raw data?
Let say:
00000000 00000000 0000000000011100000000000000000000000000000000000000000000000000
00000000000000000000000000011100000000000000000000000000000000000000000000000000
01110000100001110011111100011100001111110000111111000011111110111110000111111000
01111001110011100111111110011100011111111001111111100011111111111110001111111100
00111001110011101111111110011100011111111001111111110011111111111111001111111110
00111011111011101110000111011100111100111011110001110011100111100111011110001110
As you can see, there are few spaces between the raw data. Is it possible to eliminate/neglect it?
As from the testing, the program will still read the spaces when the program reach " in_char=file.read(); " line.
I just want the 0 and 1 data.
Thank you in advance.