Netduino home hardware projects downloads community

Jump to content


Photo

Simple delay timer


  • Please log in to reply
2 replies to this topic

#1 Jeff N

Jeff N

    New Member

  • Members
  • Pip
  • 1 posts

Posted 09 April 2015 - 10:59 PM

Hey guys -

 

The project I'm working on needs a simple wait timer but most of the execution of the program is in a do...while loop.  I don't want to put a thread.sleep because then I might miss a command in the do while.  

 

Played with the timer class some but really just need a once and done - I like the idea of an interrupt being raised -  I'm a complete noob when it comes to code -   

 

Anybody have a good suggestion?

 

j



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 10 April 2015 - 02:46 AM

Hi Jeff,

The Timer class constructor takes both dueTime (time to first timer call) and period (time between each timer call).
https://msdn.microso...y/ee432718.aspx

Just set the period to zero...and your timer will be called exactly once.

Does that get you on the right path?

Welcome to the Netduino community,

Chris

#3 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 10 April 2015 - 07:02 PM

I think you need:

Thread.Sleep( SECONDS  * 1000 ) as wait state.

 

And about timers:  In visual Basic you can program a timer very easy:
example of a reset timer (but is can do anything) together with a class:

Dim reset As New resetNetduino
Dim tcb As TimerCallback = AddressOf reset.reset

Dim resetTimer As Timer = New Timer(tcb, Nothing, 50000, Timeout.Infinite)

'bla bla bla code.....
'now dispose the timer, if you do not  dispose, reset of the Netduino will follow after 50 secs !
resetTimer.Dispose()

Public Class resetNetduino

' This do nothing but init.
Sub New()
End Sub

' This method is called by the timer delegate.
Sub reset(stateInfo As Object)
PowerState.RebootDevice(False)
End Sub

End Class






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.