Need help on programming
matthew024
Posts: 9
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
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.
You allready tested IN15 and IN3 above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
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
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