/* /0LOGBOOK 0 */ program test { #include #include #include #include var Outbin = 0 var level1 = 0 var level2 = 0 var level3 = 0 var thrh = 0 var thrl = 0 var dest1 = 0 var destm = 0 var desth = 0 var destl = 0 event equal_counter1EventEqual when counter1 = 10 sensor light2 on 2 light2 is light as percent sensor touch1 on 1 touch1 is switch as boolean event tPress_touch1EventPress when touch1.pressed sensor touch3 on 3 touch3 is switch as boolean event tPress_touch3EventPress when touch3.pressed event equal_counter1EventEqual0 when counter1 = 20 event equal_counter1EventEqual1 when counter1 = 30 macro RESET_SORT { direction [ ] [ A ] on [ A ] wait until tPress_touch3EventPress off [ A ] } macro FEED_BRICK { direction [ ] [ C ] on [ C ] for 60 reverse [ C ] on [ C ] for 60 reverse [ C ] } macro TESTCOLOR { if light2 < (thrl / 10){ Outbin = destl } else { if light2 > (thrh / 10){ Outbin = desth } else { Outbin = destm } } } macro GOTO_OUTBIN { direction [ A ] [ ] repeat (Outbin/10) { on [ A ] for 10 on [ A ] wait until tPress_touch1EventPress off [ A B C ] } } macro EJECT_BRICK { direction [ ] [ B ] on [ B ] for 20 reverse [ B ] on [ B ] for 30 reverse [ B ] } macro CALIBRATION { RESET_SORT FEED_BRICK Outbin = 10 level1 = (light2*10) GOTO_OUTBIN EJECT_BRICK RESET_SORT FEED_BRICK Outbin = 30 level2 = (light2*10) GOTO_OUTBIN EJECT_BRICK RESET_SORT FEED_BRICK Outbin = 50 level3 = (light2*10) GOTO_OUTBIN EJECT_BRICK } main { ext InterfaceType "kFreestyle" rcx_ClearTimers bbs_GlobalReset([A B C]) trigger equal_counter1EventEqual1 trigger tPress_touch3EventPress trigger tPress_touch1EventPress start variableWatcher0 start variableWatcher1 rcx_Priority( 8) trigger equal_counter1EventEqual trigger equal_counter1EventEqual0 try { counter1 = 10 } retry on fail wait until equal_counter1EventEqual1 try { repeat 8 { RESET_SORT FEED_BRICK TESTCOLOR GOTO_OUTBIN EJECT_BRICK } } retry on fail try { RESET_SORT } retry on fail try { sound 3 } retry on fail } watcher variableWatcher0 monitor equal_counter1EventEqual { rcx_Priority( 2 ) try { sound 1 CALIBRATION sound 2 counter1 = 20 } restart on fail } restart on event watcher variableWatcher1 monitor equal_counter1EventEqual0 { rcx_Priority( 2 ) try { if level1 > level2{ if level1 > level3{ if level2 > level3{ thrh = level1 thrh += level2 rcx_Divide(thrh,20) thrl = level2 thrl += level3 rcx_Divide(thrl,20) desth = 10 destm = 30 destl = 50 } else { thrh = level1 thrh += level3 rcx_Divide(thrh,20) thrl = level2 thrl += level3 rcx_Divide(thrl,20) desth = 10 destm = 50 destl = 30 } } else { thrh = level1 thrh += level3 rcx_Divide(thrh,20) thrl = level2 thrl += level1 rcx_Divide(thrl,20) desth = 50 destm = 10 destl = 30 } } else { if level1 > level3{ thrh = level1 thrh += level2 rcx_Divide(thrh,20) thrl = level3 thrl += level1 rcx_Divide(thrl,20) desth = 30 destm = 10 destl = 50 } else { if level2 > level3{ thrh = level2 thrh += level3 rcx_Divide(thrh,20) thrl = level3 thrl += level1 rcx_Divide(thrl,20) desth = 30 destm = 50 destl = 10 } else { thrh = level2 thrh += level3 rcx_Divide(thrh,20) thrl = level2 thrl += level1 rcx_Divide(thrl,20) desth = 50 destm = 30 destl = 10 } } } counter1 = 30 } restart on fail } restart on event }