<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Timer issue</title>
		<link>http://aseba.wikidot.com/forum/t-12932441/timer-issue</link>
		<description>Posts in the discussion thread &quot;Timer issue&quot; - Unexpected behaviour from a program with a timer</description>
				<copyright></copyright>
		<lastBuildDate>Sun, 06 Sep 2026 06:13:48 +0000</lastBuildDate>
		
					<item>
				<guid>http://aseba.wikidot.com/forum/t-12932441#post-4478470</guid>
				<title>Re: Timer issue</title>
				<link>http://aseba.wikidot.com/forum/t-12932441/timer-issue#post-4478470</link>
				<description></description>
				<pubDate>Fri, 24 Jan 2020 21:39:27 +0000</pubDate>
				<wikidot:authorName>EmmanuelR</wikidot:authorName>				<wikidot:authorUserId>6022232</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Thanks a lot riedo !</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-12932441#post-4475399</guid>
				<title>Re: Timer issue</title>
				<link>http://aseba.wikidot.com/forum/t-12932441/timer-issue#post-4475399</link>
				<description></description>
				<pubDate>Tue, 21 Jan 2020 16:28:12 +0000</pubDate>
				<wikidot:authorName>riedo</wikidot:authorName>				<wikidot:authorUserId>875981</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hello,</p> <p>The events (including the timer) happen when certain conditions are met, but they do not interrupt the code that is executed. A block of code is executed, and once it is done, the next block is executed if another event was triggered in the meantime.</p> <p>In your code, you have a while loop which can only be exited if you press the center button. in this loop, pressing left or right sets the motor speed, and the length of the timer, but the timer event cannot be executed until you exit the while loop. It cannot interrupt.</p> <p>Here is an example of code that behaves more like you intended I hope:</p> <div class="code"> <pre><code>var state=0 onevent buttons when button.center == 1 do state=0 timer.period[0]=0 motor.left.target = 0 motor.right.target = 0 call leds.top(32,0,0) end when button.forward == 1 do call leds.top(6,26,0) state=1 end if state==1 then when button.right == 1 do motor.right.target = -100 timer.period[0] = 1000 call leds.top(32,13,0) end if button.left == 1 then motor.right.target = 100 timer.period[0] = 1000 call leds.top(32,26,0) end end onevent timer0 motor.left.target = 0 motor.right.target = 0 timer.period[0]=0 call leds.top(6,6,32)</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-12932441#post-4468829</guid>
				<title>Timer issue</title>
				<link>http://aseba.wikidot.com/forum/t-12932441/timer-issue#post-4468829</link>
				<description></description>
				<pubDate>Tue, 14 Jan 2020 23:19:43 +0000</pubDate>
				<wikidot:authorName>EmmanuelR</wikidot:authorName>				<wikidot:authorUserId>6022232</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi all!</p> <p>I've got this program (code below) that isn't working as expected. There must me something wrong with the timer. Could you help me find out what?</p> <p><em>Scenario:</em><br /> The forward button is pressed, then the right button is pressed.</p> <p><em>Actual result:</em><br /> The right wheel start turning and keep turning indefinitely.</p> <p><em>Expected result:</em><br /> The right wheel starts turning and then stops after one second.</p> <p>Program:</p> <div class="code"> <pre><code>onevent button.center when button.center == 1 do motor.left.target = 0 motor.right.target = 0 call leds.top(32,0,0) end onevent button.forward when button.forward == 1 do call leds.top(6,26,0) while not (button.center == 1) do if button.right == 1 then motor.right.target = -100 timer.period[0] = 1000 call leds.top(32,13,0) end if button.left == 1 then motor.right.target = 100 timer.period[0] = 1000 call leds.top(32,26,0) end end end onevent timer0 motor.left.target = 0 motor.right.target = 0 call leds.top(6,6,32)</code></pre></div> <p>Best regards,<br /> Emmanuel</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>