My timer in minutes

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Rudy M
User
User
Posts: 46
Joined: Fri Aug 23, 2024 1:18 pm

My timer in minutes

Post by Rudy M »

Hello,
To learn Purebasic I'm busy to rewrite my old freebasic routines to Purebasic
For my beerbrewing proces I need a simple timer to control the mash- and boiling process.
Thats the reason its only in minutes.

Later I have the intention to make a more universal timer "hours minutes seconds milliseconds).

Can you offer an improvement/correction... then I'll read it

Rudy M

Code: Select all

Define.l Time_desired, Time_start, rest

;=======================================================================
Procedure.l Timer_min (Minutes.l)
  ;Most little value of variable 'minutes' is 1
  ;Other timers in the same listing can be: Timer_sec Timer_millisec ...
  ;You can easely extend this timer to a universal procedure
  ;p.e: Timer (hours - minutes - seconds - milliseconds)
    
  Define.l Time_difference, Time_start   ;or should it be better Protected...???
  Define.s key , key2, dummy            

  Time_start = ElapsedMilliseconds ()
  Time_end = Time_start + Minutes * 60000  ; 1 Minute = 60sec * 1000ms 
  
  ;If You do not need this info delete following 2 lines
  Debug "Starttime:" + Str(Time_start)
  Debug "Endtime..:" + Str(Time_end)
  
  Repeat
    ;-------------------------START ACTION---------------------
    ;Possible place for actions:
    ;P.E.: Read T-sensor(s)
    ;      Print on screen Temperatures
    ;      Decisions on temperatures: Heaterelement(s) ON - OFF
    ;Pratical ex.: Controlling a mash proces for beerbrewing.
    ;----------------------------------------------------------
    ;Calling other procedures:
    ;but NEVER procedures who takes longtime during actions!!!
    ;P.E. In a beerbrewing process:
    ;Play a short Alarmsound + Debug "Add + hop name + quantity"
    ;--------------------------END AKTION----------------------
         
    Time_difference = Time_end - ElapsedMilliseconds()
    
    If Time_difference <= 0  
      ;Possible place to play an alarm sound
      ;I made mp3 files;
      ;A mix of Alarmsound and my own voice:  "End Maish period one... two... three...").
      ;Here for safety You could call a procedure to put all heaterelements OFF
      ;Etc...
      
      ;Added for controlling purposes:
      ProcedureReturn Time_difference /60000   ; 0 devided by 60000 stays nul...
      Break
      
    EndIf  
    
  ForEver  
  
  ;Added for controlling purposes:
  ProcedureReturn Time_difference /60000   ; 0 devided by 60000 stays nul...

EndProcedure

Time_desired = 1 ;In Minutes

Debug "Desired time: " + Str (Time_desired) + "  Minutes"

  rest = Timer_min (Time_desired)
   
Debug "Rest_time :" + Str(rest/60)  + " minutes."
User avatar
idle
Always Here
Always Here
Posts: 5896
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: My timer in minutes

Post by idle »

you could just use AddWindowTimer but while your learning it's good to try, I sent you a threaded example of a structured timer. feel free to ask questions.
Rudy M
User
User
Posts: 46
Joined: Fri Aug 23, 2024 1:18 pm

Re: My timer in minutes

Post by Rudy M »

Wow Idle that is really professionally programmed.
I did expect that Pb in the windows part here still had possibilities.
Every day I am amazed at how gigantically extensive Pb is, You (almost) don't need any third party libs to perform a task.
But as a beginner PB user, I will try to go first and then run faster.
Thanks for the windows timer(s) I have saved them in a separate folder to examine.
Rudy M
User avatar
idle
Always Here
Always Here
Posts: 5896
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: My timer in minutes

Post by idle »

Rudy M wrote: Fri Dec 13, 2024 3:04 pm Wow Idle that is really professionally programmed.
I did expect that Pb in the windows part here still had possibilities.
Every day I am amazed at how gigantically extensive Pb is, You (almost) don't need any third party libs to perform a task.
But as a beginner PB user, I will try to go first and then run faster.
Thanks for the windows timer(s) I have saved them in a separate folder to examine.
Rudy M
That just comes from years of PB use, bare in mind it's accuracy is limited by context switching so 2 to 20ms
and I totally agree we learn by doing. Now you can get on with brewing your beer so we can drink it! :lol:
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: My timer in minutes

Post by AZJIO »

Post Reply