<?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>Program Thymio II with buttons and an array (delay-problem?)</title>
		<link>http://aseba.wikidot.com/forum/t-8741879/program-thymio-ii-with-buttons-and-an-array-delay-problem</link>
		<description>Posts in the discussion thread &quot;Program Thymio II with buttons and an array (delay-problem?)&quot; - I try to setup the Thymio so that the kids can &quot;program&quot; the Thymio with the arrow buttons and start there programm onevent button.center.</description>
				<copyright></copyright>
		<lastBuildDate>Mon, 13 Jul 2026 00:45:15 +0000</lastBuildDate>
		
					<item>
				<guid>http://aseba.wikidot.com/forum/t-8741879#post-4065258</guid>
				<title>Re: Program Thymio II with buttons and an array (delay-problem?)</title>
				<link>http://aseba.wikidot.com/forum/t-8741879/program-thymio-ii-with-buttons-and-an-array-delay-problem#post-4065258</link>
				<description></description>
				<pubDate>Thu, 22 Nov 2018 15:41:08 +0000</pubDate>
				<wikidot:authorName>riedo</wikidot:authorName>				<wikidot:authorUserId>875981</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hello,<br /> I see several problems in your code.<br /> First, you increment <tt>i2</tt> and use it as an index the array <tt>go</tt> which is size 5, but you never check that <tt>i2</tt> is not bigger than 5, so you will end up trying to write outside the array.<br /> Second, you use a while loop in your event <tt>button.center</tt>, which means the robot executes only the code in the loop until <tt>i&gt;5</tt>. <tt>i</tt> is also incremented inside the loop, and each line of code takes only a few milliseconds to execute, so what happens in your case is that the target of the motors is changed 5 times in a few milliseconds before the rest of the code is executed again, so you can only see the last command in the array being executed.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-8741879#post-4063346</guid>
				<title>Program Thymio II with buttons and an array (delay-problem?)</title>
				<link>http://aseba.wikidot.com/forum/t-8741879/program-thymio-ii-with-buttons-and-an-array-delay-problem#post-4063346</link>
				<description></description>
				<pubDate>Tue, 20 Nov 2018 07:30:51 +0000</pubDate>
				<wikidot:authorName>Mikiko Anhoco</wikidot:authorName>				<wikidot:authorUserId>4890439</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Input example:</p> <p>&lt;<br /> ^<br /> v<br /> ^<br /> o</p> <p>But the Thymio is just executing the last input, no matter hier I make use of the timer&#8230;</p> <p>But my array doesn't work as expected. The robot should drive one command after the other, instead of just executing the last command in the array.</p> <p>How do I have to fix it? <a href="http://www.ramsa.ma/UserProfile/tabid/42/userId/322104/Default.aspx">http://www.ramsa.ma/UserProfile/tabid/42/userId/322104/Default.aspx</a></p> <div> <p>var go[5] = [0,0,0,0,0]<br /> var j = 0<br /> var i<br /> var i2 = 0<br /> var richtung</p> <ol> <li>stop timer 0</li> <li>timer.period[0] = 0</li> <li>reset outputs</li> </ol> <p>call sound.system(-1)<br /> call leds.top(0,0,0)<br /> call leds.bottom.left(0,0,0)<br /> call leds.bottom.right(0,0,0)<br /> call leds.circle(0,0,0,0,0,0,0,0)</p> <p>onevent button.center<br /> when button.center == 1 do<br /> while i &lt; 5 do<br /> if go[i] == 0 then<br /> call leds.circle(32,0,0,0,0,0,0,0)<br /> motor.left.target = 300<br /> motor.right.target = 300<br /> elseif go[i] == 1 then<br /> call leds.circle(0,0,32,0,0,0,0,0)<br /> motor.left.target = 300<br /> motor.right.target = 0<br /> elseif go[i] == 2 then<br /> call leds.circle(0,0,0,0,32,0,0,0)<br /> motor.left.target = -300<br /> motor.right.target = -300<br /> #timer.period[0] = 1000<br /> elseif go[i] == 3 then<br /> call leds.circle(0,0,0,0,0,0,32,0)<br /> motor.left.target = 0<br /> motor.right.target = 300</p> <p>end</p> <p>i = i + 1<br /> end<br /> #emit pair_run 5<br /> end</p> <p>onevent button.forward<br /> when button.forward == 1 do<br /> richtung = 0<br /> go[i2] = 0<br /> i2 = i2 + 1<br /> #emit pair_run 0<br /> end</p> <p>onevent button.right<br /> when button.right == 1 do<br /> richtung = 1<br /> go[i2] = richtung<br /> i2 = i2 + 1<br /> end</p> <p>onevent button.left<br /> when button.left == 1 do<br /> richtung = 3<br /> go[i2] = richtung<br /> i2 = i2 + 1<br /> #emit pair_run 2<br /> end</p> <p>onevent button.backward<br /> when button.backward == 1 do<br /> richtung = 2<br /> go[i2] = richtung<br /> i2 = i2 + 1<br /> #emit pair_run 3<br /> end</p> <p>onevent timer0<br /> timer.period[0] = 0<br /> motor.left.target = 0<br /> motor.right.target = 0<br /> call leds.bottom.left(32,0,0)<br /> call leds.bottom.right(32,0,0)</p> </div> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>