You only need one timer. Use
Wire a non-toggled button to Start. Timeleft outputs the timer.Code:@inputs Start @outputs Timeleft @persist N interval(N) if(Start){ N = 1000 Timeleft = 30 } if(Timeleft > 0){ if(clk()){Timeleft--} }else{N = 0}
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)already thanks for the helpCode:#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}
You only need one timer. Use
Wire a non-toggled button to Start. Timeleft outputs the timer.Code:@inputs Start @outputs Timeleft @persist N interval(N) if(Start){ N = 1000 Timeleft = 30 } if(Timeleft > 0){ if(clk()){Timeleft--} }else{N = 0}
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
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.
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:interval(N)
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(Start){ N = 1000 Timeleft = 30 }
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.Code: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
yeah but it doesnt work yeah for me since i use some toggle value i think?
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
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?
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
The way I do countdown timers is usually this:
e2 Code:
@inputs Run ResetTo @outputs Time @persist Time2 interval(100) Time2 = (Time2 + 0.1) * Run 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.
Bookmarks