Shop OBEX P1 Docs P2 Docs Learn Events
Need help on programming — Parallax Forums

Need help on programming

matthew024matthew024 Posts: 9
edited 2009-07-09 02:53 in BASIC Stamp
I'm a semi-beginner and I need to know if there is a command to see if for example and·LED is on or not. I'm on the What's a microcontroller and need help. I'm making my own program and·I need to know. For the LED, I'm making this part where it has the elseif. If this button is pushed and this LED I'm talking about is on, pause for a second. That is the part I'm confounded on. Please help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-09 01:30
    Your question doesn't make a lot of sense. It always helps to attach your source program to your message so there's a context to your question.

    For example, you say that you want your program to see if an LED is on or not. How's the LED turned on? If a button turns it on, how? Directly? or does the microcontroller turn on the LED when it detects the switch on?

    There's no command to tell whether the LED is turned on. There's a way to test an I/O pin to see if it's set to output +5V or to output 0V, but that doesn't actually test for an LED or whether the LED is emitting light.
  • matthew024matthew024 Posts: 9
    edited 2009-07-09 01:38
    Here is the attached program. It is a similated stop light I created. It works but if I press the pushbutton when it is already green, it turns on the two lights on the same side, meaning the red and yellow are turned on on one side. Is there anyway to prevent that from happening?
  • dev/nulldev/null Posts: 381
    edited 2009-07-09 01:51
    I'm having some trouble understanding excactly what you want to accomplish, but this part of your code will never execute:
        ELSEIF (IN15 = 1) AND (ON GREEN_LED1)  THEN
        PAUSE 100
        ELSEIF (IN3 = 1) AND (ON GREEN_LED2) THEN
        PAUSE 100
    
    



    You allready tested IN15 and IN3 above.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-09 02:39
    I think you need to start with a simpler problem until you have a better feeling for how the Stamp and the Stamp Basic statements work.

    If you don't know the DEBUG statement, read the chapter in the Stamp Basic Syntax and Reference Manual. Put some DEBUG statements in your program that will identify where in your program it may be. See what happens when you push the pushbutton.

    There's no such thing as an ON LED statement. There is an ON statement used for something completely different. The Manual describes how it works.

    You can test the state of the Stamp's output register (connected to the I/O pins) by using OUTn the same way you use INn where n is an I/O pin number. When you do a HIGH <pin>, you set the output register bit to 1. When you do a LOW <pin>, you set the output register bit to 0. To test whether the pushbutton on pin 15 is on and the green led #1 on pin 12 has been turned on do:

    IF IN15 = 1 AND OUT12 = 1 THEN
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-09 02:53
    Something else you may not have considered ...

    In your program, you're declaring a bunch of variables to indicate the I/O pin numbers, then assigning a constant value to them. You can simplify things by just declaring those names as constants like:

    GREEN_LED_1 CON 6 ' The name GREEN_LED_1 is equivalent to the number 6
Sign In or Register to comment.