' {$STAMP BS1} ' {$PBASIC 1.0} '------------------------------------------------------ ' Triple Servo Random Movement Generator ' By Vern Graner 10-26-2004 ' Any questions to vern@graner.com ' R-04.28b '------------------------------------------------------ ' -First attaempt for Prop-1 controller '------------------------------------------------------ ' Hardware setup: ' Servos connected to pins 0-3 'Declare Variables '------------------------------------------------------ SYMBOL RESULT = W0 ' value can be 0 to 65535 SYMBOL DEST1 = B2 ' value can be 0 to 255 SYMBOL CUR1 = B3 ' value can be 0 to 255 SYMBOL DEST2 = B4 ' value can be 0 to 255 SYMBOL CUR2 = B5 ' value can be 0 to 255 SYMBOL DEST3 = B6 ' value can be 0 to 255 SYMBOL CUR3 = B7 ' value can be 0 to 255 SYMBOL DEST4 = B8 ' value can be 0 to 255 SYMBOL CUR4 = B9 ' value can be 0 to 255 'Pre set values in variables '------------------------------------------------------ RESULT = 11010 ' set initial "seed" value CUR1 = 50 ' Set all current and destination values to match DEST1 = 50 ' to force the cur=dest routines to generate a random CUR2 = 50 ' destination for all servos on first pass DEST2 = 50 CUR3 = 50 DEST3 = 50 CUR4 = 50 DEST4 = 50 '------------------------------------------------------ 'Main loop begin LOOP: IF CUR1=DEST1 THEN FetchNewDest1 'If the servo has reached it's destination fetch a new one GOTO NextTest1 ' if not, skip to next test FetchNewDest1: RANDOM RESULT 'Use RANDOM to find a new destination RESULT=RESULT // 200 'Cut it down to a usable size DEST1=RESULT 'Stuff the new destination into DEST variable DEST1=DEST1 MIN 50 'Set limits so servos do not exceed positional DEST1=DEST1 MAX 200 ' requiremenmts ' DEBUG "Cur1=",#CUR1," Dest1=",#DEST1,CR NextTest1: IF CUR2=DEST2 THEN FetchNewDest2 GOTO NextTest2: FetchNewDest2: RANDOM RESULT RESULT=RESULT // 200 DEST2=RESULT DEST2=DEST2 MIN 50 DEST2=DEST2 MAX 200 ' DEBUG "Cur2=",#CUR2," Dest2=",#DEST2,CR NextTest2: IF CUR3=DEST3 THEN FetchNewDest3 GOTO NextTest3 FetchNewDest3: RANDOM RESULT RESULT=RESULT // 200 DEST3=RESULT DEST3=DEST3 MIN 50 DEST3=DEST3 MAX 200 ' DEBUG "Cur3=",#CUR3," Dest3=",#DEST3,CR NextTest3: IF CUR4=DEST4 THEN FetchNewDest4 GOTO NextTest4 FetchNewDest4: RANDOM RESULT RESULT=RESULT // 200 DEST4=RESULT DEST4=DEST4 MIN 50 DEST4=DEST4 MAX 200 ' DEBUG "Cur4=",#CUR4," Dest4=",#DEST4,CR NextTest4: IF CUR1