Time setting

Lamtron

Member
With all of your help my timer project seems to be working. I have a question I am trying to have the timer adjust from 0 to 60 seconds and by me changing the pause time and playing with the pot I can't get it to change much. With a pause of 1000 it never shuts off. I am using a 10K pot @ 3 vdc for picaxe power. Below is the code.

SYMBOL RELAY = 2
SYMBOL POT1 = 4
SYMBOL TRIGGER = pin3

SYMBOL Temp = B1

START:
ReadADC POT1, Time 'get pot value between 0 and 255

IF TRIGGER = 0 THEN START: 'wait till the button is pushed

HIGH RELAY 'activate relay
FOR TEMP = 1 TO Time 'count from 1 to time setting
PAUSE 100 'pause 1/10 second for each count
NEXT TEMP ' next time update
LOW RELAY 'relay off
Do : loop until pin3=0
goto start
 

techElder

Well-known member
It looks like you are using the word "time" as a variable, when "time" is a PICAXE reserved word (http://www.picaxe.com/BASIC-Commands/Time-Delays/time/).

Change the variable to something like "setTime" and see if that makes it work the way you want.

Adding a side of advice ... your code will be easier to debug and read if you'll keep the same capitalization on your variables throughout your code.
 

lbenson

Senior Member
As Tex says, using "time" as if it were a normal variable confounds things. Since on the M2 devices, "time" increments once a second, that would be the reason why your loop never ended with PAUSE 1000--the variable has incremented with each pass through the loop.

You could do something like this:
Code:
SYMBOL RELAY = 2
SYMBOL POT1 = 4
SYMBOL TRIGGER = pin3

SYMBOL Temp = B1
SYMBOL PauseTime=W2

START:
  IF TRIGGER = 0 THEN START:    ' wait till the button is pushed

  ReadADC POT1, Temp            ' get pot value between 0 and 255
  PauseTime = Temp / 4 * 1000   ' pause time of 0-63 seconds
  HIGH RELAY                    ' activate relay
  PAUSE PauseTime               ' pause 0-63 seconds
  LOW RELAY                     ' relay off
  Do : loop until TRIGGER=0
  goto start
If this still seems not to perform as expected, put SERTXD("PAUSE for ",#PauseTime," seconds",cr,lf) before "HIGH RELAY" so you can see what has been calculated.
 
Top