Shop OBEX P1 Docs P2 Docs Learn Events
Need Help- Programmers wanted — Parallax Forums

Need Help- Programmers wanted

Benbo231Benbo231 Posts: 26
edited 2009-01-21 02:36 in BASIC Stamp
I cannot get this program to work-neither btn does anything


please proofread...
roll.gif·roll.gif·roll.gif·roll.gif·roll.gif·roll.gif·roll.gif·roll.gif·roll.gif·roll.gif·roll.gifroll.gifroll.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Someday Monkeys will rule the world. Then you'll be the first to go!

Comments

  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2009-01-18 15:21
    It is better to list your program in either the posting formated code block or as an attachment.·If you leave it in WORD then only those people with WORD will be·able to help you thereby limitting your chance for help.

    [color=#000000]' {$STAMP BS2}
    [/color]
    OUTPUT 0
    btn1  VAR Byte
    cnt  VAR Byte 
    loop 
    PULSOUT 12, 1000 
    PULSOUT 13, 500 
    PAUSE 15 
    BUTTON 1,0,255,250,btn1,0,noSwitch 
    OUT0=btn1 
    FOR cnt=1 TO 50 
      PULSOUT 12, 500 
      PULSOUT 13, 1000 
      PULSOUT 12, 1000 
      PULSOUT 13, 1000 
      NEXT 
      OUT0 =0 
     noSwitch: GOTO loop 
    

    I see many things wrong with your listing but without knowing more on what you are trying to do, it might not make sense to post.

    I have also attached a working 10 button program. There are better ways to press buttons but this works to take 4 push button presses and total them into a 4 digit number.
    ' 10_ButtonTest.BS2
    ' Written by Timothy Gilmore
    ' March 4th, 2006
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    Btn0            PIN     0
    Btn1            PIN     1
    Btn2            PIN     2
    Btn3            PIN     3
    Btn4            PIN     4
    Btn5            PIN     5
    Btn6            PIN     6
    Btn7            PIN     7
    Btn8            PIN     8
    Btn9            PIN     9
    ' ------------------------------------------------------------------------------
    ' Constants
    ' ------------------------------------------------------------------------------
    
    ' ------------------------------------------------------------------------------
    ' Variables
    ' ------------------------------------------------------------------------------
    btnWrk0         VAR     Byte
    btnWrk1         VAR     Byte
    btnWrk2         VAR     Byte
    btnWrk3         VAR     Byte
    btnWrk4         VAR     Byte
    btnWrk5         VAR     Byte
    btnWrk6         VAR     Byte
    btnWrk7         VAR     Byte
    btnWrk8         VAR     Byte
    btnWrk9         VAR     Byte
    Value           VAR     Byte
    Digit1000s      VAR     Byte
    Digit100s       VAR     Byte
    Digit10s        VAR     Byte
    Digit1s         VAR     Byte
    Total           VAR     Word
    
    ' ------------------------------------------------------------------------------
    ' Initialization
    ' ------------------------------------------------------------------------------
    Initialize:
    ' ------------------------------------------------------------------------------
    ' Program Code
    ' ------------------------------------------------------------------------------
    Main:
    GOSUB Get4Buttons        'Get all 4 digits from pushbuttons
    PAUSE 1000               'Display 4 digit code for 1 second
    Total = (Digit1000s * 1000) + (Digit100s * 100) + (Digit10s * 10) + Digit1s
    DEBUG DEC Total
    GOTO Main                'Repeat process
    '----- Subroutines
    Get4Buttons:
     Value = 255
     GOSUB GetButtons
     Digit1000s = Value
     Value = 255
     GOSUB GetButtons
     Digit100s = Value
     Value = 255
     GOSUB GetButtons
     Digit10s = Value
     Value = 255
     GOSUB GetButtons
     Digit1s = Value
     RETURN
    
    GetButtons:
      ' Try changing the Delay value (255) in BUTTON to see the effect of
      ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat;
      ' 255 = no auto-repeat (only one action per button press)
      '
      ' The BUTTON instruction will cause the program to branch to the next pushbutton
    
    Button0:
      PAUSE 5
      BUTTON Btn0, 0, 200, 20, btnWrk0, 0, Button1
      Value = 0
    Button1:
      PAUSE 5
      BUTTON Btn1, 0, 200, 20, btnWrk1, 0, Button2
      Value = 1
    BUTTON2:
      PAUSE 5
      BUTTON Btn2, 0, 200, 20, btnWrk2, 0, Button3
      Value = 2
    BUTTON3:
      PAUSE 5
      BUTTON Btn3, 0, 200, 20, btnWrk3, 0, Button4
      Value = 3
    BUTTON4:
      PAUSE 5
      BUTTON Btn4, 0, 200, 20, btnWrk4, 0, Button5
      Value = 4
    BUTTON5:
      PAUSE 5
      BUTTON Btn5, 0, 200, 20, btnWrk5, 0, Button6
      Value = 5
    BUTTON6:
      PAUSE 5
      BUTTON Btn6, 0, 200, 20, btnWrk6, 0, Button7
      Value = 6
    BUTTON7:
      PAUSE 5
      BUTTON Btn7, 0, 200, 20, btnWrk7, 0, Button8
      Value = 7
    BUTTON8:
      PAUSE 5
      BUTTON Btn8, 0, 200, 20, btnWrk8, 0, Button9
      Value = 8
    BUTTON9:
      PAUSE 5
      BUTTON Btn9, 0, 200, 20, btnWrk9, 0, No_Press
      Value = 9
    
    No_Press:
    IF Value = 255 THEN
      GOTO Button0
    ENDIF
    RETURN
    


  • Benbo231Benbo231 Posts: 26
    edited 2009-01-18 16:29
    it's 4 a robot- it goes 4ward until one of the buttons is pressed...

    thne it backs up and turns, then starts over. It's a modified version of the robot in the end of Electronics for dummies

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Someday Monkeys will rule the world. Then you'll be the first to go!
  • Benbo231Benbo231 Posts: 26
    edited 2009-01-18 16:31
    OUTPUT 0
    btn1· VAR Byte
    btn2· VAR Byte
    cnt· VAR Byte
    loop
    PULSOUT 12, 1000
    PULSOUT 13, 500
    PAUSE 15
    BUTTON 1,0,255,250,btn1,0,noSwitch
    BUTTON 2,0,255,250,btn2,0,noSwitch
    OUT0=btn1
    FOR cnt=1 TO 50
    · PULSOUT 12, 500
    · PULSOUT 13, 1000
    · PULSOUT 12, 1000
    · PULSOUT 13, 1000
    · NEXT
    OUT0=btn2
    FOR cnt=1 TO 50
    · PULSOUT 12, 500
    · PULSOUT 13, 1000
    · PULSOUT 12,·500
    · PULSOUT 13,·500
    · NEXT
    · OUT0 =0
    ·noSwitch: GOTO loop

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Someday Monkeys will rule the world. Then you'll be the first to go!
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2009-01-18 20:15
    Take a look at this. It is a combination of your program and the 'BUTTON' example code as found in the HELP files for the Stamp Editor.
    ' BTN_TEST2.BS2
    ' Written by Timothy Gilmore
    ' January 18, 2009
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' Connect an active-low circuit to pin P0 of the BS2. When you press the
    ' button, the servos will cause movement, then DELAy approximately one second
    ' (200 x 5 ms PAUSE) before auto-repeating at a rate of approximately 100 ms (5 x 20 ms).
     
    Btn0            PIN     0
     
    ' ------------------------------------------------------------------------------
    ' Constants
    ' ------------------------------------------------------------------------------
    
    ' ------------------------------------------------------------------------------
    ' Variables
    ' ------------------------------------------------------------------------------
     
    btnWrk0         VAR     Byte
    cnt             VAR     Byte
    
    ' ------------------------------------------------------------------------------
    ' Initialization
    ' ------------------------------------------------------------------------------
     
    Initialize:
     
    ' ------------------------------------------------------------------------------
    ' Program Code
    ' ------------------------------------------------------------------------------
     
    Main:
    'Button is not pushed here
     
    PULSOUT 12, 1000
    PULSOUT 13, 500
     
    ' Try changing the Delay value (255) in BUTTON to see the effect of
    ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat;
    ' 255 = no auto-repeat (only one action per button press)
     
    PAUSE 5
    BUTTON Btn0, 0, 200, 20, btnWrk0, 0, No_Press
    'Button is pushed so do something here
     
    FOR cnt=1 TO 50
      PULSOUT 12, 500
      PULSOUT 13, 1000
      PULSOUT 12, 1000
      PULSOUT 13, 1000
    NEXT
     
    No_Press:
    GOTO Main                'Repeat process
     
    
  • Benbo231Benbo231 Posts: 26
    edited 2009-01-21 02:36
    to get it 2 begining now...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Someday Monkeys will rule the world. Then you'll be the first to go!
Sign In or Register to comment.