Skip to content

Constant

Fab1205 edited this page Sep 11, 2018 · 12 revisions

Précédent|Home|Suivant

Braitenberg "Constant"

But :

Chaque fois qu’on donne une tappe au robot, celui-ci passe à l’état suivant : d’abord il avance, ensuite il tourne à gauche, puis à droite, puis recule, puis recommemce.

Code :

# variables for state
var state[4] = [0,0,0,0]
var new_state[4] = [0,0,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)

# subroutine to display the current state
sub display_state
	call leds.circle(0,state[1]*32,0,state[3]*32,0,state[2]*32,0,state[0]*32)

onevent tap
	if state[0] == 0 and state[1] == 0 then
		motor.left.target = 200
		motor.right.target = 200
		new_state[0] = 0
		new_state[1] = 1
	end
	if state[0] == 0 and state[1] == 1 then
		motor.left.target = -200
		motor.right.target = 200
		new_state[0] = 1
		new_state[1] = 0
	end
	if state[0] == 1 and state[1] == 0 then
		motor.left.target = 200
		motor.right.target = -200
		new_state[0] = 1
		new_state[1] = 1
	end
	if state[0] == 1 and state[1] == 1 then
		motor.left.target = -200
		motor.right.target = -200
		new_state[0] = 0
		new_state[1] = 0
	end
Clone this wiki locally