/* /0LOGBOOK 0 */ program test { #include #include #include #include var straight = 0 var brightness = 0 var step = 0 var TopStep = 0 var LookBright = 0 var vLSample = 0 var vLowStep = 0 var vTopStep = 0 var vMaxLight = 0 var vMinLight = 0 var vDirection = 0 var vTimer = 0 var vCollision = 0 sensor touch1 on 1 touch1 is switch as boolean event tPress_touch1EventPress when touch1.pressed sensor rotation2 on 2 rotation2 is rotation as angle event greater_rotation2EventHigh when rotation2 > 23 event less_rotation2EventLow when rotation2 < 1 event greater_rotation2EventHigh0 when rotation2 > 11 sensor light3 on 3 light3 is light as percent event equal_straightEventEqual when straight = -10 macro RECHTDOOR { on [ A C ] for 300 straight = -10 } macro LOOK_V10 { off [ A C ] vLSample = -10 vTopStep = -10 vLowStep = -10 vMaxLight = -10 vMinLight = 1010 on [ B ] repeat { } until greater_rotation2EventHigh reverse [ B ] repeat { vLSample = (light3*10) if vLSample > vMaxLight{ vMaxLight = vLSample vTopStep = (rotation2*10) } else { } if vLSample < vMinLight{ vMinLight = vLSample vLowStep = (rotation2*10) } else { } } until less_rotation2EventLow reverse [ B ] repeat { } until greater_rotation2EventHigh0 off [ B ] straight = 10 } macro VAR_TURN_V10 { if LookBright = 10{ tone 4000 for 10 vDirection = vTopStep } else { tone 250 for 10 vDirection = vLowStep } if vDirection = 120{ } else { vTimer = vDirection rcx_Divide(vTimer,240) if vDirection < 120{ vTimer = abs (vTimer ) * (-1) vTimer += 5 on [ A ] for (vTimer*10) } else { vTimer -= 5 on [ C ] for (vTimer*10) } } } main { ext InterfaceType "kFreestyle" rcx_ClearTimers bbs_GlobalReset([A B C]) start TouchWatcher0 start variableWatcher1 rcx_Priority( 8) trigger tPress_touch1EventPress trigger equal_straightEventEqual try { straight = 0 LookBright = -10 vCollision = 0 global dir [ ] [ A B C ] power [ B ] 1 on [ B ] for 200 rcx_Calibrate(4,2) clear Rotation2 power [ B ] 4 reverse [ B ] on [ B ] } retry on fail try { repeat { } until greater_rotation2EventHigh0 } retry on fail try { off [ B ] power [ A C ] 8 straight = 10 } retry on fail try { forever { RECHTDOOR } } retry on fail } watcher TouchWatcher0 monitor tPress_touch1EventPress { rcx_Priority( 3 ) try { bb_Backward(A, C, 100) off [ A C ] reverse [ A C ] vCollision += 10 if vCollision > 30{ vCollision = 0 if LookBright = 10{ LookBright = -10 } else { LookBright = 10 } } else { } LOOK_V10 VAR_TURN_V10 straight = 10 } restart on fail } restart on event watcher variableWatcher1 monitor equal_straightEventEqual { rcx_Priority( 2 ) try { LOOK_V10 VAR_TURN_V10 } restart on fail } restart on event }