# variables for notes var notes[6] var durations[6] var note_index = 6 var note_count = 6 var wave[142] var i var wave_phase var wave_intensity # compute a sinus wave for sound for i in 0:141 do wave_phase = (i-70)*468 call math.cos(wave_intensity, wave_phase) wave[i] = wave_intensity/256 end call sound.wave(wave) # 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) # when a note is finished, play the next note onevent sound.finished if note_index != note_count then call sound.freq(notes[note_index], durations[note_index]) note_index += 1 end onevent buttons when button.forward == 1 do motor.left.target = 500 motor.right.target = 500 end when button.center == 1 do motor.left.target = 0 motor.right.target = 0 end when button.left == 1 and button.backward == 1 do call leds.top(32,0,0) end when button.backward == 1 and button.right == 1 do call leds.top(0,32,0) end when button.left == 1 and button.right == 1 do call leds.top(0,0,32) end when button.forward == 1 and button.backward == 1 do call math.copy(notes[0:5], [440, 524, 440, 370, 311, 370]) call math.copy(durations[0:5], [7, 7, 14, 7, 7, 14]) note_index = 1 note_count = 6 call sound.freq(notes[0], durations[0]) end onevent prox when prox.ground.delta[0] < 400 and prox.ground.delta[1] < 400 do motor.left.target = -500 motor.right.target = -500 end when prox.horizontal[0] > 2000 and prox.horizontal[1] > 2000 and prox.horizontal[2] > 2000 do motor.left.target = 500 motor.right.target = -500 end when prox.horizontal[0] < 1000 and prox.horizontal[1] < 1000 and prox.horizontal[2] < 1000 do motor.left.target = 500 motor.right.target = 500 end when prox.horizontal[3] > 2000 and prox.horizontal[4] > 2000 do motor.left.target = -500 motor.right.target = 500 end when prox.horizontal[3] < 1000 and prox.horizontal[4] < 1000 do motor.left.target = 500 motor.right.target = 500 end when prox.horizontal[5] > 2000 and prox.horizontal[6] < 1000 do motor.left.target = -500 motor.right.target = 500 end when prox.horizontal[6] > 2000 do motor.left.target = 500 motor.right.target = -500 end when prox.horizontal[5] < 1000 do motor.left.target = 500 motor.right.target = 500 end when prox.horizontal[6] < 1000 do motor.left.target = 500 motor.right.target = 500 end when prox.horizontal[0] > 2000 and prox.horizontal[1] > 2000 and prox.horizontal[2] > 2000 and prox.horizontal[3] > 2000 and prox.horizontal[4] > 2000 and prox.horizontal[5] > 2000 and prox.horizontal[6] > 2000 do motor.left.target = 0 motor.right.target = 0 call math.copy(notes[0:5], [440, 524, 440, 370, 311, 370]) call math.copy(durations[0:5], [7, 7, 14, 7, 7, 14]) note_index = 1 note_count = 6 call sound.freq(notes[0], durations[0]) end