Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years ago.
why the value shows 100 when num value reaches 0, when I read from local?
I have to subract 1 from result variable..........
include the mbed library with this snippet
#include "mbed.h"
#include "SerialLCD.h"
#include "TextLCD.h"
LocalFileSystem local("local");
TextLCD lcd(p15, p16, p17, p18, p19, p20);
DigitalIn switchengine(p30);
DigitalOut myled(LED1);
Timeout pumpoff;
Timeout pumpoon;
int mintime;
float totalh;
int result;
int newvalue;
void reader();
int num= 20;
float h;
int m;
void bypass();
void save()
{
if(h>0){
FILE *fp = fopen("/local/timeleft.txt", "w"); // Open "out.txt" on the local file system for writing
fprintf(fp, "%1.2f", h);
fclose(fp);
}
if(m>0){
FILE *fp = fopen("/local/timeleft.txt", "w"); // Open "out.txt" on the local file system for writing
fprintf(fp, "%d", m/1);
fclose(fp);
}
bypass();
}
void bypass()
{
FILE *fp3 = fopen("/local/timeleft.txt", "r"); // Open "out.txt" on the local file system for writing
if (fp3 != NULL) {
char buffer[10] = {0};
char c = {0};
char *token;
int i = 0;
/* Read Chars Until End of Line */
while ((c != '\n') && (i < 10)) {
c = fgetc(fp3);
buffer[i] = c;
i++;
}
/* Get Token: Probably not needed, but Useful for More Numbers */
token = strtok(buffer, "\n");
/* String to Int Function */
float result = atof(token);
float number = result;
if(result==1){
number = result-1;
}
fclose(fp3);
lcd.locate(1,1);
lcd.printf("res= %1.2f\r\n", number);
}
}
int main()
{
myled = 0;
//Timer duration;
int newnum;
while(switchengine == 1) {
num--;
if(num <= 0)
num = 1;
wait(0.5);
lcd.cls();
lcd.locate(2,0);
lcd.printf("%d", num);
if(num < 10){
m = num;
newnum = num;
}else{
h = num/0.1;
newnum = num;
}
}
save();
}