Hackster is hosting Impact Spotlights: Robotics. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Robotics. Stream on Thursday!
Ron T.
Published © GPL3+

Low Cost 42LC RPN calculator

You can build a 42LC RPN (reverse Polish notation) calculator for about $40 with the M5 Stack Cardputer, a micro SD card and some stickers.

IntermediateWork in progress1 hour121
Low Cost 42LC RPN calculator

Things used in this project

Hardware components

Cardputer
M5Stack Cardputer
×1
Micro SD card
×1
Sticker paper
×1

Software apps and online services

Arduino IDE
Arduino IDE
https://www.arduino.cc/en/software/

Story

Read more

Code

42LC code

C/C++
To build and upload the code to the M5Stack Cardputer, first get the Arduino IDE at https://www.arduino.cc/en/software/

To setup Arduino to work with the M5Stack Cardputer, the first step is to follow the Arduino board management guidelines at:
https://docs.m5stack.com/en/arduino/arduino_board

The next step is to add the cardputer library. See https://docs.m5stack.com/en/arduino/m5cardputer/program

You can try uploading the display example before creating a new project that uses the source code below. Make sure you have the correct board and port settings in the Tools pulldown menu.
/** 42LC calculator
 copyright R. Tanikawa 2025
v. 0.8
 */

#include "M5Cardputer.h"
#include "math.h"
#include "SD.h"
#include <Complex.h>



_Complex double compa,compb,compc; 






char menuz[230][20]={"deg","rad","grad","","rect","polar","size","quiet","cres","rres","key","lclb",
"new","inv","det","tran","simq","edit","dot","cross","uvec","dim","index","editn",
"stoij","rclij","stoel","rclel","putm","getm","fix","sci","eng","all","rdx.","rdx,",
"sum+","sum","mean","wmn","sdev","cfit","allsum","linsum","","","sumreg","sumrg?",
"fcstx","fcsty","slope","yint","corr","modl","linf","logf","expf","pwrf","","best",
"a..f","hexm","decm","octm","binm","logic","and","or","xor","not","bit?","rotxy",
">deg",">rad",">hr",">hms",">rec",">pol","ip","fp","rnd","abs","sign","mod",
"sf","cf","fs?","fc?","fs?c","fc?c","comb","perm","n!","gam","ran","seed",
"lbl","rtn","input","view","aview","xeq","x?0","x?y","prom","pse","isg","dse",
"aip","xtoa","agra","pixel","beep","tone","mvar","varm","getk","menu","keyg","keyx",
"x=0?","x!=0","x<0?","x>0?","x<=0?","x>=0?","x=y?","x!=y?","x<y?","x>y?","x<=y?","x>=y?",
"prsum","prp","prv","prst","pra","prx","prusr","list","adv","prlcd","","delay",
"pon","poff","","man","norm","trace","sum+","1/x","sqrt","log","ln","xeq",
"clsum","clp","clv","clst","cla","clx","clrg","del","clky","cllcd","clmn","clall",
"<-","old","^","v","goto","->","A","B","C","D","E","F",
"llim","ulim","acc","","","integ","mata","matb","matx","","fnrm","mtnum",
"sinh","cosh","tanh","asinh","acosh","atanh","save","load","mtnum","pcount","","",
"aleng","arot","ashf","cpx?","posa","rnrm","r^","input ind","","","",""}; //34

int nextmenu[40]={1,0,3,4,2,5,7,8,9,6,
11,10,13,12,14,15,17,18,19,16,
21,20,23,24,22,25,27,26,28,29,
30,31,34,35,35,32};

int lastmenu[40]={1,0,4,2,3,5,9,6,7,8,
11,10,13,12,14,15,19,16,17,18,
21,20,24,22,23,25,27,26,28,29,
30,31,35,35,32,34};

int temparry[20];
int tonez[10]={330,440,494,554,587,659,740,831,880,1109};
int flags[4]={0,0,0,0};

char alpham[45][10]={"abcde","fghi","jklm","nopq","rstuv","wxyz","A","B","C","D","E","",
"F","G","H","I","","","J","K","L","M","","",
"N","O","P","Q","","","R","S","T","U","V","",
"W","X","Y","Z","",""};

char cmds[100][20]={"sum+","1/x","Sqrt","LOG","LN","XEQ","7","8","9","/",
"STO","RCL","RLDN","SIN","COS","TAN","4","5","6","x",
"SST","BST","x<>y","CHS","E","BSP","1","2","3","-",
"","EXIT","shift","","","ENTER","0",".","R/S","+",
"sum-","Y^X","X^2","10^X","e^X","GTO","","","","",
"CMPX","%","PI","ASIN","ACOS","ATAN","","","","",
"SST","BST","LASTx","","","","","","","",
"","OFF","","","","ALPHA","INPUT","SHOW","PRGM","VIEW",
"SINH","COSH","TANH","ASINH","ACOSH","ATANH"};

char stotbl[200][10];
char lbltbl[200][10];
int addrtbl[200];
char smenu[6][10];
int indexes[6];

char numstr[20];
char *chptr;

//char alphas[35]="234567WERTYUSDFG890IOPJKLNM,.;[-";
int alphas[35]={0,1,2,3,4,5,10,11,12,13,14,15,21,22,23,24,6,7,8,16,17,18,26,27,28,36,37,38,39,29,19,9};
int sizes[24]={4,3,3,4,2,2,2,4,3,2,
3,2,4,4,3,4,2,5,5,2, 2,3,6};

double stats[6];

double matx[10][10][10];
double prognums[100];
int mtrow[10];
int mtcol[10];
int rtnstack[100];
int rtnloc=0;
int prognumcount=0; // loc for prognums to store
int storenum=0;

double ulim=0;
double llim=0;
double accur=0.01;
double cnum=0;

int matnum=0; //indexed matrix
int mati,matj;
int progcount=0; //loc of curr used program
int cmode=0; // rec/polar complex mode
int mtnum=0; // curr available matrix to use
int solveaddr;
int lastkey=0;
int alphamode=0;
int basem=10;
int basenum=0;
int cmdd=0;
int intsolv=0;
int menunum=-1;
int tones=0; // beep mode
double mults=0;
double rnums=0.3857162904;
int colr=0; // color for display
int mcolr=0; // color for menus
int fontz=0; // font num - unused for 42LC
int keys;
int expp=0;
double num=0;
double num1=0;
int shifts=0;
int ans=0;
double stos[200]={0,0,0,0,0,0,0,0,0,0,0,0};
double stos2[200];
int stotype[200];
int pc=0;
int beeps=0;
int pgm[1500];
//int pgm1[102];
int mode=0;
int decm=0;
int gotos=0;
int scientif=0;
int scidigs=0;
int signs=1;
int idles=0;
int codes1=0;
double slope=0;
double intc=0;
int angles=0;
int gotosflag=0;
double lastx=0;
double lastx2=0;
int lastxtype=0;
int stoper=0;
int secs=0;
int dispFlag=0;
int solvemode=0;
int fnum=0;
int solvar=0;

//int zz=c_sqrt(3);
// 1=normal shift, 2=sto 3=rcl  5=exp 6=exp2 7=gto1 8=gto2 9=fix 10=sci 11=eng

double stacks[4]={0,0,0,0};
double stacks2[4]={0,0,0,0};
int dtype[4]={0,0,0,0};  //0=num, 1=complex, 2=matrix
char strs[100];
char alphastr[100]="";
//char keyz[42]="234567890-wertyuiop[asdfghjkl;@zxcvbnm,. ";
char keyz[46]="234567890-wertyuiop[asdfghjkl;@zxcvbnm,. ";
int fixs=5;

void clearPgm() {
  int i;

  for (i=0; i<20; ++i)  //20
    pgm[i*100]=5100;
    
/*  for (i=0; i<26; ++i)
    pgm[100+50*i]=4000+i;
  pgm[0]=38; */
}

void clearDsp() {
M5Cardputer.Display.fillRect(0,0,240,135,BLACK);
}

double tohms(double a) {
  int i;
  double fp,temp;
  long a1;
  int minutes;
  double seconds;
  int divs;
  Serial.println(a*3600);
//  temp=fmod(fp,fp);
  seconds=3600.0*modf(a,&temp);
 // divs=(int)a;
  //seconds=(int)((a*3600.0)-(3600.0*divs)+0.5);
//  (int)(a*3600.0)(int)(a*3600) % 3600;
Serial.println(seconds);
//  a1=(int)a;
//  fp=a-a1;
//Serial.println("%f",fp);
//  seconds=fp*3600;
  minutes=(int)(seconds/60);
  seconds=fmod(seconds,60);

//  seconds=(int)(60*((60*fp)-(int)(60*fp)));

  return temp+(minutes/100.0)+(seconds/10000.0);
}


double tohours(double a) {
  int minutes;
  double seconds,temp;
  long a1;
  double fp;

  fp=a*100.0;
  seconds=modf(fp,&temp)/36.0;
//  a1=10000*a;
//  seconds=(int)a1 % 100;
//  a1=a1/100;
  minutes=fmod(temp,100.0);
/*  fp=a-a1;
  minutes=(int)(fp*100);
  
  fp=fp*100;
  seconds=(int)((fp-minutes)*100); */
  Serial.println(minutes);
  Serial.println(seconds);
  modf(a,&temp);
  return temp+(minutes/60.0)+(seconds);
}

void bstring(int nums,char *strs) {
  int ndig;
  int i;

  ndig=0;

  if (nums>0) {
    ndig=int(1+log(nums)/log(2));
  } else {
    ndig=32;
  }
/*  if (nums==1)
    strcpy(strs,"1");
  else */
  if (ndig==0) {
    strcpy(strs,"0");
  } else {
    for (i=0; i<ndig; ++i) {
      if (1<<(ndig-i-1) & nums)
        strs[i]='1';
      else
        strs[i]='0';
    }
    strs[ndig]=0;
  }
}
void solves(int addr) { //secant solver method
  double x0=-8;
  double x1=0;
  
  double e=0.000000001;
  int N=20;
  int step=0;
  double x=0;
  double f0;
  double f1;
  double x2;
  double f2;
  int count=0;
//delay(1000);
Serial.println(solvar);
  x0=stacks[0];
  x1=stacks[1];
  intsolv=1;
  if (x0==x1) {
    x1+=15.0;
    x0-=30.0;
  }
  solvemode=1;
//  mode=2;
  while (count<50) {
    count++;
    x=x0;
    pc=addr;
//    Serial.println(x);
    stos[solvar]=x;
    mode=2;
    runProgram();
//    Serial.println(num);
    
    f0=num;

    x=x1;
    Serial.println(x);
    pc=addr;
    stos[solvar]=x;
    mode=2;
    runProgram();
//        Serial.println(stacks[0]);

    f1=num;

    if (f0==f1) {
      intsolv=0;
      solvemode=0;
      //M5Cardputer.Display.clear();
      clearDsp();
//      M5Cardputer.Display.fillRect(0,0,240,135,BLACK);
      M5Cardputer.Display.setTextFont(&fonts::FreeSerif12pt7b);
      M5Cardputer.Display.drawString("Error:  g1=g2",15,90);
//      Serial.println("Math error");
      mode=0;
      return;
    }
    x2=(x0*f1-x1*f0)/(f1-f0);
    x0=x1;
    x1=x2;
    stos[solvar]=x2;
    pc=addr;
//    mode=2;
    runProgram();
//        Serial.println(num);

    f2=num;
      
 //Serial.println(f0);
      

      
    step = step + 1;
      
    if (step > N) {
      intsolv=0;
      clearDsp();
//      M5Cardputer.Display.clear();
      M5Cardputer.Display.setTextFont(&fonts::FreeSerif12pt7b);
      M5Cardputer.Display.drawString("not convergent",15,90);
//      Serial.println("no convergence");
      solvemode=0;
      mode=0;

      return;
    }
    if (fabs(f2)<=e)
      break;
  }
//    Serial.println(x2);
    intsolv=0;
    if (count==50) {
//      M5Cardputer.Display.clear();
      clearDsp();
      M5Cardputer.Display.setTextFont(&fonts::FreeSerif12pt7b);
      M5Cardputer.Display.drawString("solution not found",15,90);
    } else {
    num=x2;
    stacks[0]=num;
    ans=1;

    dispNum(num);
    }
    mode=0;
    
    solvemode=0;
    
    return;
}


void integrate(){
  long int n,i;
  double a,b,h,x,sum=0,integ;
  double fa,fb;
  char msg[20];
 
 intsolv=1;
 if (scientif)
  n=int(pow(10,(scidigs+3)/2));
 else
  n=int(pow(10,(fixs+3)/2));
//n=10;
Serial.println(n);
  if ((n % 2)!=0)
    n+=1;
//n=100;
//a=stacks[1];
//b=stacks[0];
a=llim;
b=ulim;
Serial.println(n);
Serial.println(solveaddr);
Serial.println(solvar);
Serial.println(a);
Serial.println(b);
  h=abs(b-a)/n;
  for(i=1;i<n;i++){

    if ((i%10000)==0) {
      sprintf(msg,"integrating %d",i/10000);
      clearDsp();
//      M5Cardputer.Display.clear();
      M5Cardputer.Display.drawString(msg,15,40);
    }

  /*  M5Cardputer.update();
    if(M5Cardputer.Keyboard.isChange()) {
      
      mode=0;
      ans=1;
      stacks[0]=num;
      break;
      
    } */
    x=a+i*h;
    if(i%2==0){
      pc=solveaddr;
      stos[solvar]=x;
 //     mode=2;
      runProgram();
//      Serial.println(num);
      sum=sum+2*num;
    }
    else{
      pc=solveaddr;
      stos[solvar]=x;
//      mode=2;
      runProgram();
//      Serial.println(num);
      sum=sum+4*num;
    }
  }
  pc=solveaddr;
  stos[solvar]=a;
//  mode=2;
  runProgram();
  fa=num;

  pc=solveaddr;
  stos[solvar]=b;
//  mode=2;
  runProgram();
  intsolv=0;
  fb=num;
  integ=(h/3)*(fa+fb+sum);
   /*Print the answer */
   Serial.println(integ);
   num=integ;
   dispNum(num);
//  text(toString(integral),5,5);
}


double facts(float a) {
  double prod=1.0;
  int i;

  for (i=(int)a; i>1; --i)
    prod=prod*i;
  return prod;
}

void rolldown(){
  double temp;
  int i;

  temp=num;
  stacks[0]=stacks[1];
  stacks[1]=stacks[2];
  stacks[2]=stacks[3];
  stacks[3]=temp;

  temp=stacks2[0];
  stacks2[0]=stacks2[1];
  stacks2[1]=stacks2[2];
  stacks2[2]=stacks2[3];
  stacks2[3]=temp;

  i=dtype[0];
  dtype[0]=dtype[1];
  dtype[1]=dtype[2];
  dtype[2]=dtype[3];
  dtype[3]=i;

  dispNum(stacks[0]);
  num=stacks[0];
  ans=1;
}
void pushx(double val){
//  if (dtype[0]==1) {
    stacks[3]=stacks[2];
    stacks[2]=stacks[1];
//  }

  if (dtype[0]==1) {
    stacks[1]=stacks[0];
  } else {
  stacks[1]=val;
  stacks[0]=val;
  }

  stacks2[3]=stacks2[2];
  stacks2[2]=stacks2[1];
  stacks2[1]=stacks2[0];
//  stacks2[0]=0;

  dtype[3]=dtype[2];
  dtype[2]=dtype[1];
  dtype[1]=dtype[0];
//  dtype[0]=0;
}
void stacklift(double val){
  stacks[3]=stacks[2];
  stacks[2]=stacks[1];
  stacks[1]=stacks[0];
  stacks[0]=val;

  stacks2[3]=stacks2[2];
  stacks2[2]=stacks2[1];
  stacks2[1]=stacks2[0];
  stacks2[0]=0;

  dtype[3]=dtype[2];
  dtype[2]=dtype[1];
  dtype[1]=dtype[0];
  dtype[0]=0;
}
  
void popx(){
  stacks[1]=stacks[2];
  stacks[2]=stacks[3];

  stacks2[1]=stacks2[2];
  stacks2[2]=stacks2[3];

  dtype[1]=dtype[2];
  dtype[2]=dtype[3];
}

void clearReg(){
  int i;
  for (i=100; i<200; ++i) {
    stos[i]=0;
    stos2[i]=0;
    stotype[i]=0;
    stotbl[i][0]=0;
  }
/*  for (i=0; i<4; ++i) {
    stacks[i]=0;
    stacks2[i]=0;
    dtype[i]=0;
  } */
  num=0;
  dispNum(0);
  ans=1;
}
void setup() {
    int i;
    
    char strs1[]=".                   ";
    char xx;
    
    numstr[0]=0;

//Complex c1(10.0, -2.0);
//    lgamma(3.14);
    Serial.begin(9600);
    sprintf(strs1,"%05x",-1234);
//    bstring(32767,strs1);
    Serial.println(strs1);
     i=M5Cardputer.Power.getBatteryLevel();
    Serial.println(i);
    i=M5Cardputer.Power.getBatteryVoltage();
    Serial.println(i);

    for (i=0; i<100; ++i) {
      stotbl[i][0]=0;
      lbltbl[i][0]=0;
    }

    auto cfg = M5.config();
    M5Cardputer.begin(cfg, true);



    M5Cardputer.Display.setRotation(1);
    M5Cardputer.Display.setTextColor(GREEN);
    M5Cardputer.Display.setTextDatum(middle_left);
    M5Cardputer.Display.setTextFont(&fonts::FreeSerifBold18pt7b);
    M5Cardputer.Display.setTextSize(1);
    M5Cardputer.Display.drawString("42LC calculator",
                                   2,
                                   M5Cardputer.Display.height() / 2);
    M5Cardputer.Display.setTextFont(&fonts::FreeSerif9pt7b);
    M5Cardputer.Display.drawString("ver. 0.8",100,90);
 pgm[0]=5100;
 pgm[1]=5200;
  fileReads();
//pgm[10]=5200;
 fileReads1();
 num=stacks[0];
//    dispNum(num);
    ans=1;
  fileReads2();
  fileReads3();
  fileReads4();
  dispNum(num);

}

void fileWrites() { //program
  int i;
  char strs1[]="                      ";
  buildfilename(strs,'a');
  SD.begin();
  File files=SD.open(strs,FILE_WRITE);

  if (files==NULL) {
    SD.end();
    return;
  }
  for (i=0; i<1500; ++i) { //1500
    sprintf(strs1,"%d",pgm[i]);
    files.println(strs1);
    delay(1); }

  files.close();
  SD.end();

}

void fileWrites1() {
  int i;
  char strs1[]="                      ";
  buildfilename(strs,'b');
  SD.begin();
  File files=SD.open(strs,FILE_WRITE);
  if (files==NULL) {
    SD.end();
    return;
  }
  for (i=0; i<100; ++i) {
    sprintf(strs1,"%e",stos[i]);
    files.println(strs1); }
  for (i=0; i<4; ++i) {
    sprintf(strs1,"%e",stacks[i]);  
    files.println(strs1); }

  for (i=0; i<4; ++i) {
    sprintf(strs1,"%e",stacks2[i]);  
    files.println(strs1); }

  for (i=0; i<4; ++i) {
    sprintf(strs1,"%d",dtype[i]);  
    files.println(strs1); }


  sprintf(strs1,"%d",fixs);
  files.println(strs1);

  sprintf(strs1,"%d",scientif);
  files.println(strs1);

  sprintf(strs1,"%d",scidigs);
  files.println(strs1);

  sprintf(strs1,"%d",fontz);
  files.println(strs1);

  sprintf(strs1,"%d",beeps);
  files.println(strs1);

  sprintf(strs1,"%d",colr);
  files.println(strs1);

// more vars

  sprintf(strs1,"%d",mcolr);
  files.println(strs1);

  sprintf(strs1,"%d",prognumcount);
  files.println(strs1);

  sprintf(strs1,"%d",progcount);
  files.println(strs1);  

  sprintf(strs1,"%d",cmode);
  files.println(strs1);  

  sprintf(strs1,"%d",mtnum);
  files.println(strs1);  

  files.close();
  SD.end();
//fixs,scientif,scidigs,fontz,beeps,colr
}
void fileWrites2() { //stotbl, prognums
  int i;
  char strs1[]="                                 ";
  buildfilename(strs,'c');
  SD.begin();
  File files=SD.open(strs,FILE_WRITE);
  if (files==NULL) {
    SD.end();
    return;
  }
  for (i=0; i<100; ++i) {
    if (stotbl[i][0]==0)
      files.println("$");
    else
      files.println(stotbl[i]);
  }
  for (i=0; i<100; ++i) {
    sprintf(strs1,"%e",prognums[i]);
    files.println(strs1);
  }
  
  
  files.close();
  SD.end();
//fixs,scientif,scidigs,fontz,beeps,colr
}

void fileWrites3() { //lbltbl
  int i;
  char strs1[]="                      ";
  buildfilename(strs,'d');
  SD.begin();
  File files=SD.open(strs,FILE_WRITE);
  if (files==NULL) {
    SD.end();
    return;
  }
  for (i=0; i<100; ++i) {
    if (lbltbl[i][0]==0)
      files.println("$");
    else
      files.println(lbltbl[i]);
  }
  for (i=0; i<100; ++i) {
      sprintf(strs1,"%d",addrtbl[i]);
      files.println(strs1);
  }
  
  files.close();
  SD.end();
//fixs,scientif,scidigs,fontz,beeps,colr
}

void fileWrites4() { //matrix
  int i,j,k;
  char strs1[]="                      ";
  buildfilename(strs,'e');
  SD.begin();
  File files=SD.open(strs,FILE_WRITE);

  if (files==NULL) {
    SD.end();
    return;
  }
  for (i=0; i<10; ++i) 
    for (j=0; j<10; ++j)
      for (k=0; k<10; ++k) { 
        sprintf(strs1,"%e",matx[i][j][k]);
        files.println(strs1);
      }

  for (i=0; i<10; ++i) {
    sprintf(strs1,"%d",mtrow[i]);
    files.println(strs1);
  }
  for (i=0; i<10; ++i) {
    sprintf(strs1,"%d",mtcol[i]);
    files.println(strs1);
  }

  files.close();
  SD.end();

}
void buildfilename(char *fname,char filetype) {
  char ch1,ch2,ch3;

  if ((storenum<0) || (storenum>99))
    storenum=0;
  ch1='0'+int(storenum/10);
  ch2='0'+(storenum % 10);
  ch3=filetype;
  sprintf(fname,"/test42%c%c%c.txt",ch3,ch1,ch2);

}
void fileReads() { //pgm
  int xx;
  int i,j,k;
  char strs[]="                    ";

  j=0;
  k=0;
  SD.begin();
  buildfilename(strs,'a');
  Serial.println(strs);
  File files=SD.open(strs,FILE_READ);
  if (files==NULL)
    return;
for (i=0; i<8000; ++i) {
  xx=files.read();
//  Serial.println(xx);
 
  if (xx==-1)
    break;
  if (xx!=13) {
  strs[j]=xx;
  j+=1;
  }else{
    xx=files.read();
//    Serial.println(xx);
    strs[j]=0;
    pgm[k]=atoi(strs);
//    Serial.println(strs);
    k+=1;
    if (k>1499)
      break;
    j=0;
  }
//  delay(1);
 } 
 Serial.println("k");
 Serial.println(k);
  files.close();
  SD.end();
  for (i=0; i<15; ++i) 
    rescanlbl(i*100);
}

void fileReads1() { //stores reg
  int xx;
  int i,j,k;
  char strs[]="                          ";
  int stackmode=0;

  j=0;
  k=0;
  buildfilename(strs,'b');
  SD.begin();
  File files=SD.open(strs,FILE_READ);
  if (files==NULL)
    return;
for (i=0; i<2600; ++i) {
  xx=files.read();
//  Serial.println(xx);
 
  if (xx==-1)
    break;
  if (xx!=13) {
  strs[j]=xx;
  j+=1;
  }else{
    xx=files.read();
//    Serial.println(xx);
    strs[j]=0;
    if (stackmode==0)
      sscanf(strs,"%lf",&stos[k]);
    else if (stackmode==1)
      if (k<4)
        sscanf(strs,"%lf",&stacks[k]);
      else if (k<8)
        sscanf(strs,"%lf",&stacks2[k-4]);
      else if (k<12)
        sscanf(strs,"%d",&dtype[k-8]);
      else {
        sscanf(strs,"%d",&temparry[k-12]);
      }
    

//    stos[k]=atof(strs);
//    Serial.println(strs);
    k+=1;
    if (k==100) {
      stackmode=1;
      k=0;
    }
    j=0;
  }
//  delay(1);
 } 
 files.close();
  SD.end();
  storeitems();
}

void storeitems() {
  fixs=temparry[0];
  scientif=temparry[1];
  scidigs=temparry[2];
  fontz=temparry[3];
  beeps=temparry[4];
  colr=temparry[5];
  mcolr=temparry[6];
  prognumcount=temparry[7];
  progcount=temparry[8];
  cmode=temparry[9];
  mtnum=temparry[10];

 if (colr==0)
    M5Cardputer.Display.setTextColor(GREEN);
  else if (colr==1)
    M5Cardputer.Display.setTextColor(RED);
  else if (colr==2)
    M5Cardputer.Display.setTextColor(WHITE);
}
void fileReads2() { //stores
  int xx;
  int i,j,k;
  char strs[]="                          ";
  int stackmode=0;
  int readmode=0;

  j=0;
  k=0;
  buildfilename(strs,'c');
  SD.begin();
  File files=SD.open(strs,FILE_READ);
  if (files==NULL)
    return;
for (i=0; i<8600; ++i) {
  xx=files.read();
//  Serial.println(xx);
 
  if (xx==-1)
    break;
  if (xx!=13) {
  strs[j]=xx;
  j+=1;
  }else{
    xx=files.read(); //read newln
//    Serial.println(xx);
    strs[j]=0;
    if (readmode==0) {
      sscanf(strs,"%s",&stotbl[k]);
      if (stotbl[k][0]=='$')
        stotbl[k][0]=0;
    } else {
      sscanf(strs,"%lf",&prognums[k]);
    }
      
    

//    stos[k]=atof(strs);
//    Serial.println(strs);
    k+=1;
    if (k==100) {
      k=0;
      readmode=1;
    }

    j=0;
  } //else
//  delay(1);
 } //for
 files.close();
  SD.end();
}

void fileReads3() {
  int xx;
  int i,j,k;
  char strs[]="                          ";
  int stackmode=0;
  int count;

  j=0;
  k=0;
  buildfilename(strs,'d');
  SD.begin();
  File files=SD.open(strs,FILE_READ);
  if (files==NULL)
    return;
for (i=0; i<3600; ++i) {
  xx=files.read();
//  Serial.println(xx);
 
  if (xx==-1)
    break;
  if (xx!=13) {
  strs[j]=xx;
  j+=1;
  }else{
    xx=files.read(); //read newln
//    Serial.println(xx);
    strs[j]=0;
    if (stackmode==0) {
      sscanf(strs,"%s",&lbltbl[k]);
      if (lbltbl[k][0]=='$')
        lbltbl[k][0]=0;
    } else {
      sscanf(strs,"%d",&addrtbl[k]);
    }
      
    

//    stos[k]=atof(strs);
//    Serial.println(strs);
    k+=1;
    if (k==100) {
...

This file has been truncated, please download it to see its full contents.

Credits

Ron T.
3 projects • 0 followers

Comments