SD card space by percents

Hello, i am trying to write program that mesures SD card used space by persents x.xx%.
i am stuck at geting incard file or files size as row number, if i use fileinfo exemple i get suze but can not use it as row data.
Can anyone help?

Have you looked at the CardInfo example?

yes, i tryed to take LS_SIZE from Cardinfo exemple but number that i get is arount 3000 times smaler then actual file size file 86MB (89084692) but i get 23109

i think i got ansver in SDfat librarie

Can you share that answer with us?
that is what the forum is all about :wink:

unfortunatly i can get persentige only in exemple sdfat>sdinfo but when i try to transfer that block in my program it starts to complaib that i can not use } after first line of exemple program block,if i try to move block to wery bigining of program it just dasnt work and starts to crash arduino uno
lcd starts rebooting ewry 2 minits or sow. it seams that arduini trys to boot exemple block
but fails…. and i can not find problem

hello agin. I managet to write code as insertion to athers (nead few modifications to work on diferent programs). One thing left, to make grafick like in here: Arduino LCD horizontal progress bar using custom characters | electronicsblog.net

full exemple code:

#include <SdFat.h>

// Arduino Ethernet Shield = pin 4
const int iSDPin = 10;

// Global card and file variables
SdFat sd;
SdFile file;

int i = 1;  // Global counter

//
// Display space available on SD card
//




   
  uint32_t cardSize;

// global for card erase size
uint32_t eraseSize;



void setup() {
  // Setup serial monitor
  Serial.begin(4800);
  // Wait 
  delay(100);
  // Some declaring text
  Serial.println("\nSD Card - SD Fat Library - File date-time stamp testing");
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.

}

void loop(){
  
    if (!sd.begin(iSDPin, SPI_HALF_SPEED))
    Serial.println("NO SDCARD");
    
  Serial.println("\nReading free space...");
  float FreeKB = sd.vol()->freeClusterCount();
       FreeKB *= sd.vol()->blocksPerCluster()/2;
  float Fullcap  = sd.vol()->clusterCount();
       Fullcap *= sd.vol()->blocksPerCluster()/2;
  float Usedspace  = Fullcap-FreeKB; 
  float Procent = Usedspace/Fullcap*100;
   Serial.print("Fullcap: ");
   Serial.print(Fullcap);
   Serial.println(" KB");
   Serial.print("Free space: ");
   Serial.print(FreeKB);
   Serial.println(" KB");
   Serial.print("Usedspace: ");
   Serial.print(Usedspace);
   Serial.println(" KB");
   Serial.print("Procent: ");
   Serial.print(Procent);
   Serial.println("  %"); 


  if ((0)<Procent<(25)){Serial.println(" ");}
  if ((25)<Procent<(50)){Serial.println("[][]");}
  if (50<Procent<75){Serial.println("[][][]");}
  if (75<Procent<100){Serial.println("[][][][]");}




  delay(100);
}

if anyone could solve this problem, i would realy aprisiate help. Problem is in last if part
it prints all [] without considering persentage.
(i put a loth of hours in to making this program work,and as noob at programing i'am proud of my atcheavment)

yeah... you need to look into ELSE IF and understand how to use conditional arguments

 if ((0)<Procent<(25)){Serial.println(" ");}
  if ((25)<Procent<(50)){Serial.println("[][]");}
  if (50<Procent<75){Serial.println("[][][]");}
  if (75<Procent<100){Serial.println("[][][][]");}

something like...

  if (Procent < 25 )
  {
    Serial.println(" ");
  }
  else if (Procent< 50 )
  {
    Serial.println("[][]");
  }
  else if (Procent< 75 )
  {
    Serial.println("[][][]");
  }
  else 
  {
    Serial.println("[][][][]");
  }

thanks i will try it.

Hello again. I have one more problem: button push, after push i nead to wait till loop restarts and just then arduino notisis buton but whatever i program runs to slow.

If anyone can help i would realy aprisiate. Thanks in advance:)

You have a lot going on in that loop, so no wonder it takes a long time for the buttons to get read. You may need to put the reading section into their own function and call it every so often in your code. Of course, you'll need to detect the difference between "when" a button is pressed versus a button is being held down.

Unrelated...

Do this:

settemp = settemp - 10;

;

Instead of this silly bit:

(settemp --);
(settemp --);
(settemp --);
(settemp --);
(settemp --);
(settemp --);
(settemp --);
(settemp --);
(settemp --);
(settemp --);

Can anyone post exemple of button function that would cower 4 buttons?