Closed Matteode closed 10 years ago
Hi Nick! I am trying to use your library (BigNumber) but i have a problem. I'm trying to read numbers from a sd card and to take last value assigning it to a variable . I stored values as BigNumber with this sketch:
File myfile; BigNumber pot=A3, input1, input2, d1, d2, valoreatt, valoreacc=0;
void printBignum (BigNumber n){ char * s = n.toString (); Serial.println (s); free (s); } // end of printBignum
void setup() {
Serial.begin(9600); pinMode(10, OUTPUT); //verifico l'esistenza di una memory card if (!SD.begin(10)) { Serial.println("Card failed"); return; } Serial.println("card inizialized"); BigNumber::begin (20); // initialize library input1 = analogRead(pot);
}
void loop() {
if (valoreacc<1){ input2 = analogRead(pot); d1 = BigNumber (input2) / BigNumber (1023); d2 = BigNumber (d1) * BigNumber (d1) * BigNumber (d1); valoreatt = BigNumber (d2) / BigNumber (125) / BigNumber (1000); valoreacc = BigNumber (valoreatt) + BigNumber (valoreacc); Serial.print ( "input: " ); printBignum (input2); Serial.print ( " valoreatt: " ); printBignum (valoreatt); Serial.print ( " valoreacc: " ); printBignum (valoreacc); // memorizzo il danno sulla sd card myfile = SD.open("valori.csv", FILE_WRITE); if (myfile) { myfile.println( valoreacc ); myfile.close(); } input1=input2; delay(1500); } else { Serial.print( "stop" ); }
An example of numbers stored is this:
0.00000069004655222191 0.00000138009310444382 0.00000207013965666573 0.00000276018620888764 0.00000345023276110955 0.00000414027931333146 0.00000483032586555337 0.00000552037241777528 0.00000621041896999719 0.00000690046552221910 0.00000759051207444101 0.00000828055862666292 0.00000897060517888483 0.00000966065173110674
Then I tried to take last value with this sketch:
File myFile;
BigNumber valore;
void setup(){ Serial.begin(9600); Serial.println("Initializing SD card..."); pinMode(10, OUTPUT); digitalWrite(10, 1); BigNumber::begin (20); // initialize library
if (!SD.begin(10)) { Serial.println("initialization failed!"); }
char c; String inString = String();
myFile = SD.open("valori.csv"); if (myFile) { while (myFile.available()) {
while(c != -1) { c = myFile.read(); if(!myFile.available()) break; if (c == '\n') inString = ""; inString += c; } } myFile.close();
// -----------questa è la tua ultima riga ---------- Serial.println(inString); //debug //--------------------------------------------------
valore = inString.toInt(); Serial.print ( " valore: " ); printBignum (valore);
void loop(){ }
It finds last value but i don't succeed to assign it to variable "valore" to do then others math operations. It gives me 0.
Answered here:
http://forum.arduino.cc/index.php?topic=85692.105
Hi Nick! I am trying to use your library (BigNumber) but i have a problem. I'm trying to read numbers from a sd card and to take last value assigning it to a variable . I stored values as BigNumber with this sketch:
include "BigNumber.h"
include
include
File myfile; BigNumber pot=A3, input1, input2, d1, d2, valoreatt, valoreacc=0;
void printBignum (BigNumber n){ char * s = n.toString (); Serial.println (s); free (s); } // end of printBignum
void setup() {
}
void loop() {
}
An example of numbers stored is this:
0.00000069004655222191 0.00000138009310444382 0.00000207013965666573 0.00000276018620888764 0.00000345023276110955 0.00000414027931333146 0.00000483032586555337 0.00000552037241777528 0.00000621041896999719 0.00000690046552221910 0.00000759051207444101 0.00000828055862666292 0.00000897060517888483 0.00000966065173110674
Then I tried to take last value with this sketch:
include "BigNumber.h"
include
include
File myFile;
BigNumber valore;
void printBignum (BigNumber n){ char * s = n.toString (); Serial.println (s); free (s); } // end of printBignum
void setup(){ Serial.begin(9600); Serial.println("Initializing SD card..."); pinMode(10, OUTPUT); digitalWrite(10, 1); BigNumber::begin (20); // initialize library
if (!SD.begin(10)) { Serial.println("initialization failed!"); }
char c; String inString = String();
myFile = SD.open("valori.csv"); if (myFile) { while (myFile.available()) {
}
// -----------questa è la tua ultima riga ---------- Serial.println(inString); //debug //--------------------------------------------------
valore = inString.toInt(); Serial.print ( " valore: " );
printBignum (valore);
}
void loop(){
}
It finds last value but i don't succeed to assign it to variable "valore" to do then others math operations. It gives me 0.