+ Reply to Thread
Results 1 to 9 of 9

Thread: countdown timer?

  1. #1
    Lurker cursed666 is on a distinguished road cursed666's Avatar
    Join Date
    May 2008
    Posts
    30

    Smile countdown timer?

    hi how do you make a countdown timer? cus currently i use several timers wich start every second but somehow it often get's screwed up =/

    does anyone know how to make a better timer?

    i currently got it like this(it's a small part of my code and pretty buggy somehow)
    Code:
    #Screen Time
    if(clk("30")) {TLeft = 30,timer("29",900)}
    if(clk("29")) {TLeft = 29,timer("28",900)}
    if(clk("28")) {TLeft = 28,timer("27",900)}
    if(clk("27")) {TLeft = 27,timer("26",900)}
    if(clk("26")) {TLeft = 26,timer("25",900)}
    if(clk("25")) {TLeft = 25,timer("24",900)}
    if(clk("24")) {TLeft = 24,timer("23",900)}
    if(clk("23")) {TLeft = 23,timer("22",900)}
    if(clk("22")) {TLeft = 22,timer("21",900)}
    if(clk("21")) {TLeft = 21,timer("20",900)}
    if(clk("20")) {TLeft = 20,timer("19",900)}
    if(clk("19")) {TLeft = 19,timer("18",900)}
    if(clk("18")) {TLeft = 18,timer("17",900)}
    if(clk("17")) {TLeft = 17,timer("16",900)}
    if(clk("16")) {TLeft = 16,timer("15",900)}
    if(clk("15")) {TLeft = 15,timer("14",900)}
    if(clk("14")) {TLeft = 14,timer("13",900)}
    if(clk("13")) {TLeft = 13,timer("12",900)}
    if(clk("12")) {TLeft = 12,timer("11",900)}
    if(clk("11")) {TLeft = 11,timer("10",900)}
    if(clk("10")) {TLeft = 10,timer("9",900)}
    if(clk("9")) {TLeft = 9,timer("8",900)}
    if(clk("8")) {TLeft = 8,timer("7",900)}
    if(clk("7")) {TLeft = 7,timer("6",900)}
    if(clk("6")) {TLeft = 6,timer("5",900)}
    if(clk("5")) {TLeft = 5,timer("4",900)}
    if(clk("4")) {TLeft = 4,timer("3",900)}
    if(clk("3")) {TLeft = 3,timer("2",900)}
    if(clk("2")) {TLeft = 2,timer("1",900)}
    if(clk("1")) {TLeft = 1,timer("0",900)}
    if(clk("0")) {Tleft = 0}
    
    already thanks for the help

  2. #2
    Wirezard

    Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,151

    Default Re: countdown timer?

    You only need one timer. Use

    Code:
    @inputs Start
    @outputs Timeleft
    @persist N
    interval(N)
    
    if(Start){
    N = 1000
    Timeleft = 30
    }
    
    if(Timeleft > 0){
    if(clk()){Timeleft--}
    }else{N = 0}
    
    Wire a non-toggled button to Start. Timeleft outputs the timer.
    Last edited by Matte; 06-09-2009 at 06:23 AM.
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr


    Wire FPGA

  3. #3
    Lurker cursed666 is on a distinguished road cursed666's Avatar
    Join Date
    May 2008
    Posts
    30

    Default Re: countdown timer?

    could you please explain it a bit?
    i don't really know how it works and what it exactly does exept that if start (which is the button) get's activated it'll get something with Timeleft 30 and if timeleft is greater than 0 it'll clock timeleft -- (asfar as i remember it means -1) untill it's 0 O-o is that right? or am i just messed up?

    and it starts should start with a timer or something cus it start's if "Safe" is not equal to 1 and it doesnt work with if(Safe != 1) {} stuff to start it =/ i also tried a simple timer between it but i got no idea how to get it to work D: could someone tell me how?
    Last edited by cursed666; 06-09-2009 at 07:07 AM.

  4. #4
    Wirezard

    Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,151

    Default Re: countdown timer?

    Code:
    interval(N)
    
    This sets the interval to the variable N. The interval is an inbuilt timer in the E2, and the number in the interval function decides how many milliseconds the E2 should wait before executing again.


    Code:
    if(Start){
    N = 1000
    Timeleft = 30
    }
    
    If the button is pressed, this sets the variable N (the interval) to 1000 (one second). It also resets the Timeleft variable to 30.

    Code:
    if(Timeleft > 0){
    if(clk()){Timeleft--}
    }else{N = 0}
    
    If the Timeleft variable is greater than 30 and this execution was caused by the interval, then Timeleft is decremented by one(Timeleft-- is the same as Timeleft = Timeleft - 1). If Timeleft is equal to 0 then it stops the expression from counting down by setting N (interval) to 0.
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr


    Wire FPGA

  5. #5
    Lurker cursed666 is on a distinguished road cursed666's Avatar
    Join Date
    May 2008
    Posts
    30

    Default Re: countdown timer?

    yeah but it doesnt work yeah for me since i use some toggle value i think?

  6. #6
    Wirezard

    Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,151

    Default Re: countdown timer?

    That expression was meant for non-toggled buttons..

    For toggled buttons use:

    Code:
    @inputs Start
    @outputs Timeleft
    @persist N
    interval(N)
    
    if(~Start&Start){
    N = 1000
    Timeleft = 30}
    
    if(Start){
    
    if(Timeleft > 0){
    if(clk()){Timeleft--}
    }}else{N = 0}
    
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr


    Wire FPGA

  7. #7
    Lurker cursed666 is on a distinguished road cursed666's Avatar
    Join Date
    May 2008
    Posts
    30

    Default Re: countdown timer?

    thanks alot is there a way to stop it btw? since reset() resets the whole E2 so how could i instantly shut it down or set it to 0 or reset to 30 xD?

  8. #8
    Wirezard

    Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte is just really nice Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,151

    Default Re: countdown timer?

    Add this line:

    Code:
    if(Reset){
    N = 0
    Timeleft = 30}
    
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr


    Wire FPGA

  9. #9
    Banned Nicolai1 will become famous soon enough Nicolai1's Avatar
    Join Date
    Nov 2008
    Location
    Denmark.
    Posts
    1,303

    Default Re: countdown timer?

    The way I do countdown timers is usually this:

    e2 Code:
    1. @inputs Run ResetTo
    2. @outputs Time
    3. @persist Time2
    4. interval(100)
    5. Time2 = (Time2 + 0.1) * Run
    6. Time = max(abs(Time2-ResetTo), 0)

    When Run is false (0) it will reset to whatever value you have inputted to the ResetTo value.
    When Run is true (1) it will count down until it hits 0 and then stop.

+ Reply to Thread

Similar Threads

  1. countdown
    By woo482 in forum Technical Support
    Replies: 4
    Last Post: 10-20-2008, 02:57 PM
  2. A countdown
    By Lieutent Slappy Moose in forum Technical Support
    Replies: 8
    Last Post: 07-30-2008, 12:23 AM
  3. Timed Countdown Detonator (Circuit Diagram)
    By evileliminator in forum Wiremod Tutorials
    Replies: 9
    Last Post: 07-12-2007, 02:27 AM
  4. Countdown Timer and Activator
    By teriaki in forum Wiremod General Chat
    Replies: 3
    Last Post: 05-28-2007, 07:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots