Shop OBEX P1 Docs P2 Docs Learn Events
Question regarding Spin IF statement with Pushbutton — Parallax Forums

Question regarding Spin IF statement with Pushbutton

NWCCTVNWCCTV Posts: 3,629
edited 2013-04-20 20:15 in Propeller 1
I am trying to start a couple servos when a button is pushed. I am not sure what is wrong with my code but I am sure my PB circuit is correct. The code compiles just fine but the servos do not turn.
OBJ
   servo :     "PropBOE Servos"                        'Servo control object  
CON
  _clkmode        = xtal1 + pll16x           ' Feedback and PLL multiplier
  _xinfreq        = 5_000_000                ' External oscillator = 5 MHz
  PushButton      = 3                        ' Pushbutton Input Pin
PUB main                         ' Main method
 
   'repeat
      if [PushButton] == 1    ' wait for pushbutton to be pushed  
       servo.Set(15, 200)  ' Start Servo on pin 15 Counterclockwise
       servo.Set(14,-200)  ' Start Servo on pin 14 Clockwise
      else
       servo.stop          ' Stop Servo on pin 15
       servo.stop          ' Stop Servo on pin 14

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-20 18:54
    NWCCTV wrote: »
    I am trying to start a couple servos when a button is pushed. I am not sure what is wrong with my code but I am sure my PB circuit is correct. The code compiles just fine but the servos do not turn.
    OBJ
       servo :     "PropBOE Servos"                        'Servo control object  
    CON
      _clkmode        = xtal1 + pll16x           ' Feedback and PLL multiplier
      _xinfreq        = 5_000_000                ' External oscillator = 5 MHz
      PushButton      = 3                        ' Pushbutton Input Pin
    PUB main                         ' Main method
     
       'repeat
          if PushButton == 1    ' wait for pushbutton to be pushed  
           servo.Set(15, 200)  ' Start Servo on pin 15 Counterclockwise
           servo.Set(14,-200)  ' Start Servo on pin 14 Clockwise
          else
           servo.stop          ' Stop Servo on pin 15
           servo.stop          ' Stop Servo on pin 14
    
    Why do you have the repeat statement commented out? The body of your loop will only run once.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 19:02
    I just did that to see if I could get it to work, which I could not.
  • kuronekokuroneko Posts: 3,623
    edited 2013-04-20 19:11
    NWCCTV wrote: »
    I just did that to see if I could get it to work, which I could not.
    Shouldn't that read:
    if ina[PushButton][COLOR="#D3D3D3"]{== 1}[/COLOR]
    
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 19:33
    I just did that to see if I could get it to work, which I could not.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 19:39
    if ina[PushButton]{== 1}
    This does not work either.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 19:47
    I think this may be a resistor issue. What value resistor should I be using between the pushbutton and the PropBOE pin 3?
  • kuronekokuroneko Posts: 3,623
    edited 2013-04-20 20:01
    Does your servo object (source?) need some form of initialisation (start/init)?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 20:15
    No. If I remove the IF statement and compile the servos turn as they are suppose to. It is after I put the IF statement in that it stops working. I have my pushbutton circuit wired exactly like the diagram here. I am using the same resistors that it says to use. Am I using the wrong circuit for this application or what? EDIT: Problem Solved. It was an indentation issue. I can not believe how sensitive Spin is to indentation. Thanks for the help.
Sign In or Register to comment.