if.....then
genoneracing
Posts: 3
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
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
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:
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?
I just need a little direction
Activity #3 shows how to use a pushbutton, read it with the Stamp, and control a blinking LED.
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.