Page 58 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 58

Amphibionics 03  3/24/03  8:11 AM  Page 37
                                         Chapter 3 / Microcontrollers and PIC Programming
                        switch_r          VAR PORTA.4
                        switch_l          VAR PORTA.3
                                                                                   frog-test.bas program
                                                                                   listing (continued)
                        led_l               VAR PORTB.1                            PROGRAM 3.1
                        led_r               VAR PORTB.0
                        piezo              VAR PORTB.4
                        '------------------------------------------------------------------------------------------------------------------------------
                        low servo_l
                        low servo_r
                        start:
                        for temp1 = 1 to 10
                           SOUND piezo, [80,4,100,2]
                           low led_l
                           low led_r
                           pause 50
                           high led_l
                           high led_r
                        next temp1
                        SOUND piezo, [100,4,120,2,80,2,90,2]
                        low led_l
                        low led_r
                        rotate:
                        servo_pos_r = 170
                        gosub right_servo
                        servo_pos_l = 130
                        gosub left_servo
                        goto rotate
                        '------------------------------------------------------------------------------------------------------------------------------


                        ' subroutines to set servos
                        both_servo:
                            for timer1 = 1 to 15
                            pulsout servo_l,servo_pos_l
                            pulsout servo_r,servo_pos_r
                            pause 6
                            next timer1
                        return
                        left_servo:
                            for timer2 = 1 to 10


                                                                                                  37
   53   54   55   56   57   58   59   60   61   62   63