Shop OBEX P1 Docs P2 Docs Learn Events
if.....then — Parallax Forums

if.....then

genoneracinggenoneracing Posts: 3
edited 2011-12-01 07:05 in BASIC Stamp
I am trying to take a constant output(pin 15) into a momentary no switch that when closed is connected to pin 14
this would then trigger pin 13 to turn on and operate an external circuit for .5 second.
I have the loop so that at any time the switch can be triggered.
Here is the code I have so far, the circuit just cycles on and off as if there was no if...then statement
please help
' {$STAMP BS2sx}
DEBUG"project program"
MAIN
HIGH 15
IF IN14=1 THEN START
START:
LOW 13
PAUSE 500
LOW 13
ELSE
LOW 13
ENDIF
GOTO MAIN

Comments

  • AImanAIman Posts: 531
    edited 2011-11-30 20:55
    My first suggestion to you is to read carefully what you have written. Personally I would change it to read something like this -

    Unless your going to put more code in you could simply say

    If IN 14 = 1 then
    High 13
    Pause 500
    Low 13
    Pause 500
    High 13
    End if

    And just for kicks try experimenting with High or low 14 instead of IN14=1

    Oh ya - and it looks like you labled Main and Start: differently. Note the : And unless your going to be putting more code in you don't neet Start:
  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-30 21:00
    This looks like a school project. You're going to have to study the Stamp Manual some more and the What's a Microcontroller? tutorial. Both are downloadable from Parallax for free if you don't have them.

    Some critiques ...

    This isn't going to compile, so it certainly won't cycle on and off ... where's the colon after MAIN? ELSE and ENDIF are not allowed in PBasic 2.0. Read the Stamp Manual (around page 43) about the compiler directives $STAMP and $PBASIC.

    What do you think the IF statement does?

    If you want pin 13 to turn on, what in your program do you think will do that?
  • genoneracinggenoneracing Posts: 3
    edited 2011-11-30 21:12
    I have read the Stamp Manual and the What's a Microcontroller? tutorial several times.
    I just need a little direction
  • AImanAIman Posts: 531
    edited 2011-11-30 21:17
    I just realized I combined a couple of languages, my bad. In short you need to word the If statment to match the specifics of Pbasic.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-30 21:34
    Start with Activity #2 in What's a Microcontroller? That will show you how to turn an I/O pin on and off.

    Activity #3 shows how to use a pushbutton, read it with the Stamp, and control a blinking LED.
  • genoneracinggenoneracing Posts: 3
    edited 2011-11-30 22:16
    Ok I did the activites and got the result shown, however my switch does not have nc & no contacts. It is just a simple contact switch. How can I alter the code to read this input?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-01 07:05
    The examples in What's a Microcontroller? use Vdd for the power source for the switch. From what I understand about your problem, the difference is that you're using an I/O pin (pin 15) as the power source and you need to set the state of the switch so that it provides the +5V (approximately) that Vdd would provide. So ...

    1) Your program needs to be set up essentially like the one in Activity #3 with any changes needed to conform to your project description

    2) You need to substitute the output of pin 15 for Vdd

    3) When your program initializes itself, it needs to set pin 15 to produce approximately 5V (how would you do that based on what you've read?)

    It sounds like your switch has NO (normally open) contacts. What's a Microcontroller? shows examples with both NO and NC (normally closed) contacts, but most of the examples only need NO contacts.
Sign In or Register to comment.