Shop OBEX P1 Docs P2 Docs Learn Events
atari controller — Parallax Forums

atari controller

frosliefroslie Posts: 67
edited 2005-07-07 18:04 in BASIC Stamp
Help a novice please - sometimes easy things just miss me.

Anyway, I have built what I believe will be a functioning circuit to link an atari controller to A BS2.

The problem is the code.· I understand how to set the pins on the STAMP to HIGh or LOW - easy enough. I do not understand for this project how I can read the pin to see HIGH or LOW.·

The controller is basically a series of five buttons. They are normally HIGH until the joystick forces them to LOW. If I can read the button to see it go·LOW -·with an IF statement or something I will be set.

Any suggestions?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-07-07 05:44
    froslie -

    Both the PBASIC Stamp Manual (free for the download) and the PBASIC Help file are quite clear on the use of the IF statement, so I'm not sure where you're having a problem. Here is the start of some simple switch checking code:

    ' {$PBASIC 2.5}

    ' Assign Pin ports 0-4 to Switches 0-4
    Sw0 PIN 0 : Sw1 PIN 1 : Sw2 PIN 2 : Sw3 PIN 3 : Sw4 PIN 4

    ' Set all Pin ports to INPUT mode
    Input Sw0 : Input Sw1 : Input Sw2 ; Input Sw3 : Input Sw4

    Begin: 'Presume multiple keys can be pressed
    'Check each switch to see if it's LOW (0)

    IF Sw0 = 0 GOSUB Process_Sw0
    IF Sw1 = 0 GOSUB Process_Sw1
    IF Sw2 = 0 GOSUB Process_Sw2
    IF Sw3 = 0 GOSUB Process_Sw3
    IF Sw4 = 0 GOSUB Process_Sw4

    GOTO Begin

    Process_Sw0:
    .....
    RETURN

    Process_Sw1:
    .....
    RETURN

    END

    etc.

    Regards,

    Bruce Bates
  • frosliefroslie Posts: 67
    edited 2005-07-07 05:55
    Bruce,

    I do understand the IF statement - I meant to mention it simply as an example of my limited experience using the Stamp.

    I have not used switches. The code looks great and I believe this should start me out in excellent condition.

    Very much appreciation for the help.

    Pete Froslie
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 12:04
    Just a comment on Bruce's example: You do not have to assign pins as inputs UNLESS they were previously assigned as outputs (not the case here).· I mention this because as your program grows and code space becomes tight you'll want to eliminate any unnecessary commands.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-07-07 12:55
    I believe the Atari controller only gives you 'contacts'. If you look at the 'BUTTON' command, I believe there is a circuit there for using open/close contacts. You'll need a 10K 'Pull-up' resistor and a 220 ohm resistor, and the pin-out of the Atari controller, to implement a circuit which can properly read the contact positions.

    And yes, you'll use an IF statement, and you also may need some debouncing. I wouldn't use the BUTTON statement myself, as you'll probably want to read the positions of all the switches at the same time.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-07 15:08
    Hello,

    ·· My recommendation would be to tie the lines to a port on the BASIC Stamp and read the entire port at once.· It would be easy to catch diagonal movement (2 switches pressed at once).· You could do an INA for example, then read the bits.· You would also be able to read the fire button pressed at the same time as movement.· You would need the pullup resistors though.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • frosliefroslie Posts: 67
    edited 2005-07-07 16:15
    I tried the code Bruce mentioned up above last night - it works. I do have 100K pullup resisitors in the circuit, so I believe I will attempt the new suggestions as well. To see which responds the best.

    thanks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 18:04
    I've attached a demo code and schematic that should help -- it scans the joystick using a subroutine, providing a way to debounce all five inputs at the same time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.