;; simple.txt
;;
;; Lego Robot Design Studio
;; simple SCIBORG code for day 1

menu 1 [fwd-until-bump]
menu 2 [left-until-bump]
menu 3 [right-until-bump]
menu 4 [go-backward]
menu 5 [go-straight]
menu 6 [turn-left]
menu 7 [turn-right]

to fwd-until-bump
    go-straight
    waituntil front-bumper?
    stop-motion 
    play-song
end

to left-until-bump
    turn-left
    waituntil front-bumper?
    stop-motion 
    beep
end

to right-until-bump
    turn-right
    waituntil front-bumper?
    stop-motion 
    beep
end

to go-backward
    left-wheel on thatway 
    right-wheel on thatway
end

to go-straight
    left-wheel on thisway 
    right-wheel on thisway
end

to turn-left
    left-wheel off
    right-wheel on thisway
end

to turn-right
    right-wheel off
    left-wheel on thisway
end

to stop-motion
  left-wheel off
  right-wheel off
end

to left-wheel
  a,
end

to right-wheel
  b,
end

to front-bumper?
    output switch 7
end

to back-bumper?
    output switch 8
end

to play-song
  loop[
    wait 6
    repeat 3 [play_note 90 1 1]
    play_note 86 7 5
    repeat 3 [play_note 88 1 1]
    play_note 85 7 5
    repeat 3 [play_note 90 1 1]
    play_note 86 1 1
    repeat 3 [play_note 91 1 1]
    play_note 90 1 1
    repeat 3 [play_note 98 1 1]
    play_note 95 7 5
    repeat 3 [play_note 90 1 1]
    play_note 85 1 1
    repeat 3 [play_note 91 1 1]
    play_note 90 1 1
    repeat 3 [play_note 100 1 1]
    play_note 97 7 5
  ]
end

to play_note :frequency :duration :wait
	note :frequency :duration
	wait :wait
end
