Hi all,
first time poster but long time reader and user
anyway i have a problem with math, im trying to convert feet to metres on a button press. at the minute i have an array counting from 0.0ft to 10.6 ft and the corresponding metre code in a switch case like the example, the switch case points to a function under as void one(); (see the example).
now the obvious problem straight away is 12 inches times 10 feet = a lot of switch cases and a bloated code. but does make it easy writing to sd card and lcd screen,
I tried several ways to count up but none work, i dont know enough about arrays and bits to even start a code, i have tried examples and studying the process of it but it just doesnt click?
I know there is a simple way to count up through this range without hundreds of lines of code. can anybody help me with this? i cant post my code as it keeps changing forms and its way to long but an example of my switch case is as follows
//example
switch (count){ //my generic switch code, counts up with button press
case 1:
one(); //points to below example shortened
break;
}
//void one as example, excuse the mistakes its from memory and does work
void one(){
lcd.clear();
lcd.setCursor(0,0);
lcd.write ("0.1ft or 0.03 mtr);
myfile.(stat.txt,READ_WRITE);
myfile.write ("0.01ft or 0.03mtr")
myfile.close();
}
but how does that count up?
metre =feet /3.28
but..
how do i use that statement to produce results as well as convert between the two in a button press? i thought seeing as its climbing through an array of sorts, i would need seperate lcd prints and sd writes?
i currently have,
turn on,
feet or metre //buttonpress
count up and show on lcd //buttonpress
count down and show on lcd //buttonpress
press enter-save to sd and show on lcd //buttonpress
id like a variable to be able to use anywhere like
int magical = 0;
magical = count;
count = inch;
inch = 1.00;
feet = inch / 12;
metre / feet/3.28
insert magical conversion code here
count up in metres or feet
ive been on this for ages and cannot find a soluton within my knowledge and heavy googling just helped confuse me more on bits and thisnumber++thatnumber,++this number?!?!?!?
im not an ignorant person and i love a challenge but i can not figure this out!
At this point, you will need to format the output; create the string "0.1ft or 0.03 mtr" # where the "0.1" is replaced with feet converted to a string and "0.03" is meters converted to a string.
# Note: "mtr" is not the correct abbreviation for meter.
thanks for the detailed reply, i wish i understood it
so if i have a float, all i seem to be doing with the count number is dividing it?
and do i convert the "string" to an val? or dec, so lcd.write ("feet,VAL,metre,VAL1); ?
it seems i cant get around the math behind this? or the logic of how n it works,
i know this seems a bit of a pain especially since you gave such a detailed answer but would you be able to explain it? briefly is fine, I just dont how dividing it so many times yields a conversion?
thankyou
its cool if you cant, it its late to be fair,thanks
phillmybuttons:
thanks for the detailed reply, i wish i understood it
Maybe it will make sense in the morning.
so if i have a float, all i seem to be doing with the count number is dividing it?
Yes. Each count increments by one. Dividing that by ten gives you feet. Meters = feet / 3.28
and do i convert the "string" to an val? or dec, so lcd.write ("feet,VAL,metre,VAL1); ?
No. Split your lcd.writes See the example in the code block below.
it seems i cant get around the math behind this? or the logic of how n it works,
i know this seems a bit of a pain especially since you gave such a detailed answer but would you be able to explain it? briefly is fine, I just dont how dividing it so many times yields a conversion?
thankyou
its cool if you cant, it its late to be fair,thanks
// lcd example
// clear the screen and position cursor
lcd.write("Ft "); // write the first part
lcd.write(feet); // the variable feet found with count / 10
lcd.write(" M ");
lcd.write(meters); // meters = feet / 3.28