Page 205 - Robots Androids and Animatrons : 12 Incredible Projects You Can Build
P. 205

version.  In-group  variances  in  CdS  sensors,  drive  motors,  robot
                                structure, and the like can be adjusted for or modified in the pro-
                                gram.
                        Program 1
                                ‘Microcontroller 1
                                start:
                                high 4:low 4  ‘Blink LED
                                b7 = 0
                                button 5,0,255,0,b7,1,avoid  ‘Check for obstacle
                                pot 7, 255, b0  ‘Read CdS cell 1
                                pot 6, 255, b1  ‘Read CdS cell 2
                                If b0 <= 250 then skip  ‘Is it dark enough to sleep?
                                If b1 >= 250 then slp  ‘Yes
                                skip:   ‘No
                                if b0 > 25 then skip2  ‘Is it too bright to live?
                                if b1 < 25 then avoid  ‘Yes
                                skip2:   ‘No
                                if b0 = b1 then straight  ‘Light is equal; go straight
                                if b0 > b1 then greater  ‘Check light intensity
                                if b0 < b1 then lesser  ‘Check light intensity
           184                  straight:
                                high 0: high 1: low 2  ‘Communicate to microcontroller 2
                                goto start  ‘To go straight
                                greater:
                                b2 = b0   b1  ‘Check numerical difference
                                if b2 > 10 then rt  ‘If more than 10, turn right
                                goto straight  ‘If not, go straight
                                lesser:
                                b2 = b1   b0   ‘Check numerical difference
                                if b2 > 10 then lt  ‘If more than 10, turn left
                                goto straight  ‘If not, go straight
                                rt:   ‘Turn right, send
                                high 0: low 1: low 2  ‘Communication to microcontroller 2
                                goto start
                                lt:   ‘Turn left, send
                                low 0:high 1: low 2  ‘Communication to microcontroller 2
                                goto start
                                Slp:   ‘Go asleep, send
                                low 0: low 1: low 2  ‘Communication to microcontroller 2
                                goto start
                                avoid:   ‘Avoid mode, send
                                low 0:low 1: high 2  ‘Communication to microcontroller 2
                                goto start
                                                       Team LRN
            Chapter eight
   200   201   202   203   204   205   206   207   208   209   210