Announcement

Collapse
No announcement yet.

Can i storage my variables?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can i storage my variables?

    Hi,
    I need a code that is capable of storaging my variables, and then load it again in the next use. I am using the SK-4Duino-24.
    My code so far:
    Code:
    void Import(){
    
      word fp;
        char str[80],str2[10];
          int m=0, j=0,i=0,n=0,Exists=0;
       char dtm[100];
      fp = Display.file_Open("programs.txt", 'r');
      if(fp == NULL){
            Display.gfx_MoveTo(10,30) ;
    
          Display.putstr("Error");
      }
      Display.file_Close(fp);
      if(Display.file_Exists(fp)){
      Exists=1;
    
      }
      else
      {
        fp = Display.file_Open("programs.txt",'w');
        Display.file_Write("0 0 0 0 0\n0 0 0 0 0 \n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",100,fp);
        Display.file_Close(fp);
        Exists=1;
    
    
      }
     if(Exists==1){
        if( fgets (str, 100, fp)!=NULL ) {
    
          puts(str);
       }
       Display.file_Close(fp);
       for(i=0;i<=strlen(str);i++){
          if(str[i]== "/n"){
            for(j=0;j<=m;j++){
              str2[j] = str[i+m];
    
            }
            m = 0;
            n++;
          }
          m++;
       strcpy( dtm, str2 );
       sscanf( dtm, "%d %d %d  %d %d",&program[n].iNvoltas, &program[n].iNgiros, &program[n].iTamanho, &program[n].iContract,&program[n].iVelocidade );
    
                                  }
      return 0;
      }
      else
      {
      while(1);
      }
      
    }
    As you can see, I need a .txt that storages five variables of eight structs (40 variables). The code it is compiling just fine, but the screen freezes at the "Error" situation. Why? How can I solve that loading error? There is any other way of storaging variables at the SD card? Please help.

  • #2
    Hello,

    I tested your code on my end and I found that the errors were coming from if(Display.file_Exists(fp)).

    This needs a string parameter and fp is declared as a word, I replaced 'fp' with "programs.txt" and it seem to have run smoothly.

    The 4Duino 24 is essentially similar to a Picaso module that's being controlled by an Arduino Host controller, that being said, you may consult this application note for additional reference.

    I hope this helps.

    Best regards,
    Michael

    Comment

    Working...
    X