Page 204 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 204

Chapter 7: Ser v o Motors and Extending the Ser v o Control System             183


                             PUB init
                               dira[RIGHT_FRONT_PIN] := 1
                               dira[LEFT_FRONT_PIN]  := 1
                               dira[RIGHT_REAR_PIN]  := 1
                               dira[LEFT_REAR_PIN]   := 1

                             PUB start(num)                    ‘num is the parameter passed from
                                                                           mode
                               case num
                                 0 :
                                    cognew(mode0,@stack)            ‘start a fresh cog for
                                                                        flashing the LED strips
                                    mode0
                                 1 :
                                    cognew(mode1,@stack)
                                    mode1
                                 2 :
                                    cognew(mode2,@stack)
                                    mode2

                                 PUB mode0                          ‘Flashes just the LED strips
                                                                        on the forward booms
                               outa[RIGHT_FRONT_PIN]   := 1
                               outa[LEFT_FRONT_PIN]    := 1
                               outa[RIGHT_REAR_PIN]    := 0
                               outa[LEFT_REAR_PIN]     := 0
                               waitcnt(WAIT_CNT + cnt)
                               outa[RIGHT_FRONT_PIN]~               ‘Toggle the pin
                               outa[LEFT_FRONT_PIN]~

                             PUB mode1                              ‘Flashes all the LED strips
                               outa[RIGHT_FRONT_PIN]   := 1
                               outa[LEFT_FRONT_PIN]    := 1
                               outa[RIGHT_REAR_PIN]    := 1
                               outa[LEFT_REAR_PIN]     := 1
                               waitcnt(WAIT_CNT + cnt)
                               outa[RIGHT_FRONT_PIN]~
                               outa[LEFT_FRONT_PIN]~
                               outa[RIGHT_REAR_PIN]~
                               outa[LEFT_REAR_PIN]~

                             PUB mode2                              ‘No LED strips are flashed
                               outa[RIGHT_FRONT_PIN]   := 0
                               outa[LEFT_FRONT_PIN]    := 0
                               outa[RIGHT_REAR_PIN]    := 0
                               outa[LEFT_REAR_PIN]     := 0
   199   200   201   202   203   204   205   206   207   208   209