Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program Thymio II with buttons and an array (delay-problem?) #883

Open
budumlu opened this issue Sep 22, 2018 · 2 comments
Open

Program Thymio II with buttons and an array (delay-problem?) #883

budumlu opened this issue Sep 22, 2018 · 2 comments

Comments

@budumlu
Copy link

budumlu commented Sep 22, 2018

I try to setup the Thymio so that the kids can "program" the Thymio with the arrow buttons and start there programm onevent button.center. Input example:

<
^
v
^
o

But the Thymio is just executing the last input, no matter hier I make use of the timer...

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.

How do I have to fix it?

var go[5] = [0,0,0,0,0]
var j = 0
var i
var i2 = 0
var richtung
# stop timer 0
# timer.period[0] = 0
# reset outputs
call sound.system(-1)
call leds.top(0,0,0)
call leds.bottom.left(0,0,0)
call leds.bottom.right(0,0,0)
call leds.circle(0,0,0,0,0,0,0,0)


onevent button.center
	when button.center == 1 do
		while i < 5 do
			if go[i] == 0 then
				call leds.circle(32,0,0,0,0,0,0,0)
				motor.left.target = 300
				motor.right.target = 300
			elseif go[i] == 1 then
				call leds.circle(0,0,32,0,0,0,0,0)
				motor.left.target = 300
				motor.right.target = 0
			elseif go[i] == 2 then
				call leds.circle(0,0,0,0,32,0,0,0)
				motor.left.target = -300
				motor.right.target = -300
				#timer.period[0] = 1000
			elseif go[i] == 3 then
				call leds.circle(0,0,0,0,0,0,32,0)
				motor.left.target = 0
				motor.right.target = 300
				
			end
			
			i = i + 1
		end
		#emit pair_run 5
	end


onevent button.forward
	when button.forward == 1 do
		richtung = 0
		go[i2] = 0
		i2 = i2 + 1
		#emit pair_run 0
	end


onevent button.right
	when button.right == 1 do
		richtung = 1
		go[i2] = richtung
		i2 = i2 + 1
	end


onevent button.left
	when button.left == 1 do
		richtung = 3
		go[i2] = richtung
		i2 = i2 + 1
		#emit pair_run 2
	end


onevent button.backward
	when button.backward == 1 do
		richtung = 2
		go[i2] = richtung
		i2 = i2 + 1
		#emit pair_run 3
	end

onevent timer0
	timer.period[0] = 0
	motor.left.target = 0
	motor.right.target = 0
	call leds.bottom.left(32,0,0)
	call leds.bottom.right(32,0,0)
@davidjsherman
Copy link
Collaborator

Hi Torsten,

Do your Thymios have the dequeue native function library? It was designed to make it easy to build queues of actions to be executed sequentially.

@budumlu
Copy link
Author

budumlu commented Sep 27, 2018

Oooh, I think that's what I`m searching for...it was hard to find in the documentation...https://www.thymio.org/en:asebastdnativedeque Thanks!

But I can hardly figure out, how I could make use of it properly...could you please give me more hints, how to handle my problem with deqeue? And how can I know, wether my Thymios have the dequeuelibrary or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants