How to read analog signals?


Results 1 to 24 of 24

Threaded View

  1. #15
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default How about this way?

    Here's something untested you can try. Two methods of rapid fire but you also need to add a 330 Ohm resistor between the button and the input so the PIC can sense a press then drive the same pin as an output even if you keep holding the button low.
    I used the names pulse_fire and rapid_fire just to make them seperate.
    If it does work for you, adjust the PAUSE times to suit your needs.
    Code:
    ' This one fires off 5 shots per press or continueously if button held
    pulse_fire:                 
        i=0                     ' Reset increment counter
        TRISIO = %00000001      ' Port 0 input, rest outputs
        while GPIO.0=1: Wend    ' Wait here until button pressed
        TRISIO = %00000000      ' Port 0 now an output
            for i=1 to 5        ' Set number of rapid fires per button press
                low GPIO.0      ' Hold output LOW
                pause 50        ' Held LOW for 50ms
                high GPIO.0     ' Turn OFF output
                pause 50        ' Keep OFF for 50 ms
            next i              ' 
    goto pulse_fire             ' Go back, continue if button still pressed or 
                                ' wait until pressed again.
                                
    ' This one just continueously fires as long as button is pushed
    rapid_fire:
        TRISIO = %00000001      ' Port 0 input, rest outputs
        while GPIO.0=1: Wend    ' Wait here until button pressed
        TRISIO = %00000000      ' Port 0 now an output
                low GPIO.0      ' Hold output LOW
                pause 50        ' Held LOW for 50ms
                high GPIO.0     ' Turn OFF output                                     
                pause 50        ' Keep OFF for 50 ms
    goto rapid_fire             ' Go back, continue as long as button pressed
    Here's the schematic to the resistor add on:
    Attached Images Attached Images
    Louie

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 08:14
  2. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 10:38
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 12:20
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 07:34
  5. analog read
    By swordman in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 12th August 2004, 20:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts