Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:03 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : trying to "split" temperature

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:23am 21 Sep 2018
Copy link to clipboard 
Print this post

I'm trying to split my indoor and outdoor temperature readings because the decimal point is too big and it makes the display look "not as good as it could"

My two lines of code are
[code]Text 170,155, STR$(val(temp1$),2,1)+"`C" , LB,4, 2,rgb(223,159,54) , RGB(128,128,128) 'Outdoor Temp

Text 170,215, STR$(tempr(11),2,1)+"`C", LB,4, 2, RGB(203,168,24) , RGB(128,128,128) 'Indoor Temp[/code]


I thought it would be

[quote]Text 170,155, LEFT$(val(temp1$),2,1,2))+"`C" , LB,4, 2,rgb(223,159,54) , RGB(128,128,128) ' LEFT DIGITS
Text 170,155, RIGHT$(val(temp1$),2,1,1))+"`C" , LB,4, 2,rgb(223,159,54) , RGB(128,128,128) ' Decimal digit
and
Text 170,215, LEFT$(val(tempr(11),2,1,1))+"`C", LB,4, 2, RGB(203,168,24) , RGB(128,128,128) 'LEFT DIGITS
Text 170,215, RIGHT$(val(tempr(11),2,1,1))+"`C", LB,4, 2, RGB(203,168,24) , RGB(128,128,128) 'DECIMAL digit[/quote]

but no matter what combinations I try I always get an error and it doesn't work
Edited by lew247 2018-09-22
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 10:04am 21 Sep 2018
Copy link to clipboard 
Print this post

temp$ = "25.75"

print left$(temp$,2)
print right$(temp$,2)

print val(left$(temp$,2))
print val(right$(temp$,2))

run

25
75

25
75
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 10:19am 21 Sep 2018
Copy link to clipboard 
Print this post

  PicFan said   temp$ = "25.75"

print left$(temp$,2)
print right$(temp$,2)

print val(left$(temp$,2))
print val(right$(temp$,2))

run

25
75

25
75

That won't work because I need to limit both temp and tempr (ds1820b) temp to 1 decimal place
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 10:29am 21 Sep 2018
Copy link to clipboard 
Print this post

temp = 25.75
tmp$ = 30.25

print left$(str$(temp,2,2),2)
print mid$(str$(temp,2,2),4,1)

print left$(tmp$,2)
print mid$(tmp$,4,1)

print "As value:"val(left$(tmp$,2)) * 2

print "DS18B20:"left$(str$(tempr(pin),2,2),2)

run

25
7

30
2

As value: 60

DS18B20: 27

This is not a good solution (neg. numbers etc.), I'll keep trying !!!Edited by PicFan 2018-09-22
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:30am 21 Sep 2018
Copy link to clipboard 
Print this post

I still have a problem

While print val(left$(temp1$,2)) works

It doesn't make certain that temp1$ will always have 2 places before the decimal point
If the temp was 13.23° it would print 13 which is correct
but
if the temp was 2.35° it would print 2. which is wrong

I also need it to print the zero if the temp is 0° which this won't do


Also the DS1820B

print mid$(tempr(11),4,1)
WHile this works IF there are 2 numbers before the decimal point
it won't work if there is only 1 or the first digit is zero

Hope that made sense


 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 12:07pm 21 Sep 2018
Copy link to clipboard 
Print this post


temp10%=CINT(temp*10)
print str$(temp10%\10,2)
print temp10% mod 10
Edited by matherp 2018-09-22
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 01:52pm 21 Sep 2018
Copy link to clipboard 
Print this post

  matherp said  

temp10%=CINT(temp*10)
print str$(temp10%\10,2)
print temp10% mod 10


Thanks Peter
I had considered that and yes it would be a lot simpler and easier
but I'd like to keep the decimal place (1 place)
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 04:19pm 21 Sep 2018
Copy link to clipboard 
Print this post

Try this, i hope, i have you understand ?


Do

Input temp
x$ = str$(temp,2,2)
if (temp < 0) then
vz$="-"
else
vz$="+"
endif
nk$ = mid$(x$,instr(1,x$,".")+1,1) 'xx.7
vk$ = vz$ + str$(abs(fix(temp),1,0)
print vk$" C "nk$
nk$ = mid$(x$,instr(1,x$,".")+1,2) 'xx.75
print vk$" C "nk$

loop


run
? 5.75

+5 C 7
+5 C 75

? -5.75

-5 C 7
-5 C 75

? -0.75

-0 C 7
-0 C 75
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025