#chameleon remote control var temp var rc5_speed_l var rc5_speed_t var vmin=-600 var vmax=600 var red[DIFFERENT_COLORS] var green[DIFFERENT_COLORS] var blue[DIFFERENT_COLORS] var ground[DIFFERENT_COLORS] var color_select = 0 var color_search var ground_min var running_mode = MODE_PLAY #first color: none red[0]=0 green[0]=0 blue[0]=0 #second color: yellow red[1]=14 green[1]=9 blue[1]=0 #thirs color: green red[2]=0 green[2]=20 blue[2]=0 call leds.circle(0,0,0,0,0,0,0,0) call leds.prox.h(0,0,0,0,0,0,0,0) call leds.rc(0) call leds.temperature(0, 0) sub setmotor call math.min(rc5_speed_t, rc5_speed_t, vmax) call math.max(rc5_speed_t, rc5_speed_t, vmin) call math.min(rc5_speed_l, rc5_speed_l, vmax) call math.max(rc5_speed_l, rc5_speed_l, vmin) motor.left.target = rc5_speed_l + rc5_speed_t motor.right.target = rc5_speed_l - rc5_speed_t onevent buttons when button.left==1 do running_mode = MODE_RECORD color_select = color_select+1 if color_select== DIFFERENT_COLORS then color_select=0 end call leds.top(red[color_select], green[color_select], blue[color_select]) end when button.center==1 do running_mode = MODE_RECORD ground[color_select]=prox.ground.delta[0] end when button.right==1 do running_mode = MODE_PLAY end callsub setmotor onevent prox if running_mode == MODE_PLAY then ground_min = 1000 #high value for color_search in 1:DIFFERENT_COLORS do if abs(prox.ground.delta[0]-ground[color_search-1])<abs(ground_min) then ground_min=prox.ground.delta[0]-ground[color_search-1] call leds.top(red[color_search-1], green[color_search-1], blue[color_search-1]) end end end onevent rc5 if rc5.command !=0 then if rc5.command == 2 or rc5.command == 80 or rc5.command == 32 then #react to "number 2", "move cursor upwards" and "channel up" if rc5_speed_t!=0 then rc5_speed_t = 0 else rc5_speed_l = rc5_speed_l+200 end elseif rc5.command == 4 or rc5.command == 85 or rc5.command == 17 then #react to "number 4", "move cursor left" and "decrease volume" rc5_speed_t = -200 elseif rc5.command == 8 or rc5.command == 81 or rc5.command == 33 then #react to "number 8", "move cursor downward"s and "channel down" if rc5_speed_t!=0 then rc5_speed_t = 0 else rc5_speed_l = rc5_speed_l-200 end elseif rc5.command == 6 or rc5.command == 86 or rc5.command == 16 then #react to "number 6", "move cursor right" and "increase volume" rc5_speed_t = 200 elseif rc5.command == 5 or rc5.command == 87 or rc5.command == 13 then #react to "number 5", "acknowledge" and "master mute" rc5_speed_t = 0 rc5_speed_l = 0 end rc5.command = 0 end