Help_store temp into temporary fixed variable

Okay, yet again I'm having stupid problems there is probably a simple answer for.
What I need for my project is to take the "Temp" variable (temp numeral is stored there) and put the current number, designated by a button press into a temporary variable that does not change until rewritten..... basically push a button for temp 1...say point A'
and another button for temp 2 point b'...in another area....storing A' and B' into two variables "fixed" to compare.
Right now if I store temp into anything it changes with the temp. So I'm stumped.
 

oracacle

Senior Member
just use
let variable = temp

that will copy whatever is in temp into the variable, and wont change until you do something else with the variable
 
The variable will change with temperature I need to convert to a fixed number that's read at the time button is presses
 
Temp probe = temp (constantly changing)
Button = records temp value at time of button press
The stored value does not deviate as temp changes because it's been converted to a fixed numeral number stays the same until there's another button press to store new value I need code ideas for that
 

Rick100

Senior Member
Temp probe = temp (constantly changing)
Button = records temp value at time of button press
The stored value does not deviate as temp changes because it's been converted to a fixed numeral number stays the same until there's another button press to store new value I need code ideas for that
You should probably post your whole program and how you have the button and other hardware hooked up.
 
Then again if there's no need to run that subroutine it might store it until subroutine is run again you might breeze right I'll try it
 

lbenson

Senior Member
Code:
do
  readtemp c.0,b1
  if pinc.1 = 1 then
    b2 = b1
    sertxd("New temperature saved: ",#b2,cr,lf)
    do loop while pinc.1 = 1  ' wait until button released
  endif
loop
 
init: pause 500
main:
readtemp c.1,b0
pause 10
if pinc.2 = 1 then high b.4 let b1 = b0 'pinc.2 = button b.4 = led
sertxd ("Temp1 = ",b1,cr,lf) 'display stored temp
pause 400
low b.4
pause 500
end if
debug
goto main
okay this code like others has a problem..... the button has to have a long press to be recognized any ideas on how to make the code react to the button instantly?
 

lbenson

Senior Member
There's no reason this code should take any significant time to respond to a button press (except perhaps for "debug"). How long? How long if you omit the "debug" statement?

Try putting some output before "main:" to make sure the picaxe is not repeatedly restarting, like 'sertxd("Start",cr,lf)'.

Since you have no button-release code, if you press the button for more than a second, the "if" statement will be true on the next pass, and the if code will be repeated.

For clarity when posting, try putting your code within [ code] [ /code] tags (without the spaces). This retains your formatting.
Code:
init: pause 500
  sertxd("Start",cr,lf)
main: 
   readtemp c.1,b0
   pause 10
   if pinc.2 = 1 then 
     high b.4 
     let b1 = b0 'pinc.2 = button b.4 = led
     sertxd ("Temp1 = ",b1,cr,lf) 'display stored temp
     pause 400
     low b.4
     pause 500
   end if
 '  debug
   goto main
 

Rick100

Senior Member
From the "readtemp" documentation: "The conversion takes up to 750ms". You can't do anything about the times it takes for the "readtemp". You could put the "readtemp" in between your "if" and "endif" so it only executes when the button is pressed. I also added the # symbol in your sertxd command so b1 will be printed as a readable number.

Like this:
Code:
init: pause 500
main:

pause 10
if pinc.2 = 1 then
	high b.4
	readtemp c.1,b0
	let b1 = b0 'pinc.2 = button b.4 = led
	sertxd ("Temp1 = ",#b1,cr,lf) 'display stored temp
	pause 400
	low b.4
	pause 500
end if
debug
goto main
 
okay..... yes i know you wouldnt think there would be a lag in response but it was neverending however ...... i solved my own problem...

'this code works!!

start0:
pause 500
readtemp c.1,b0
pause 200
debug b0
goto start0
start1:
If pinc.2 = 1 then StTemp
low b.4
goto start1
StTemp:
let b1 = b0
sertxd ("Temp1 = ",#b1,cr,lf)
high b.4
pause 500
low b.4
goto start1
 
Last edited:
From the "readtemp" documentation: "The conversion takes up to 750ms". You can't do anything about the times it takes for the "readtemp". You could put the "readtemp" in between your "if" and "endif" so it only executes when the button is pressed. I also added the # symbol in your sertxd command so b1 will be printed as a readable number.

Like this:
Code:
init: pause 500
main:

pause 10
if pinc.2 = 1 then
	high b.4
	readtemp c.1,b0
	let b1 = b0 'pinc.2 = button b.4 = led
	sertxd ("Temp1 = ",#b1,cr,lf) 'display stored temp
	pause 400
	low b.4
	pause 500
end if
debug
goto main
so that's why i couldnt get a number on the sertx output lol thank you
 

Rick100

Senior Member
how are ya'll displaying your code so neatly?? retyping it in format .....i copy and paste ?...
While in the programming editor, choose "select all" from the "edit" menu. This will highlight all the code. Then choose "copy for forum" from the "edit" menu to put the selected text into the clipboard, wrapped in code tags. Then just right click and paste into the reply box.
 
Using parallel processing to constantly search for pressed button...(concept out of picaxe manual "bike alarm"

Code:
 "kid tested and mother approved"
Const: symbol Temp = b0	 
start0:
	pause 500
	readtemp c.1,b0        'store temp in var' b0
	let Temp = Temp*9/5+32 'convert to farenheit
	pause 10
	debug 
	goto start0
start1:
	If pinc.2 = 1 then StTemp 'if buttons pushed goto store temp
	goto start1
StTemp:
	high b.4               'light led
	let b1 = Temp
	sertxd ("Temp1 = ",#Temp,cr,lf)	
	pause 500
	low b.4
	goto start1
 
Last edited:

lbenson

Senior Member
how are ya'll displaying your code so neatly?? retyping it in format .....i copy and paste ?...
Or, as I said in post 10, type the tags "[ code]" before your code and "[ /code]" after (without the spaces--and also without the quotes).

Congratulations.
 

oracacle

Senior Member
ctrl+a is select all, and using ctrl+shift+c is the same as edit>copy for forum. ctrl+v is past and cotrol+c is cnormal copy.

i find it alot easier and faster to use keyboard shortcuts than going through the menus
 
Top