Hey guys, I’m taking a look at the code, and I’ve got a small question. On this part:
'========== MAIN PROGRAM =====================================================
'=============================================================================
'---------- Input & Output Declarations --------------------------------------
Output COMB
Input COMA
Input COMC
Output 7 'define Basic Run LED on RC => out7
Output 8 'define Robot Feedback LED => out8 => PWM1 Green
Output 9 'define Robot Feedback LED => out9 => PWM1 Red
Output 10 'define Robot Feedback LED => out10 => PWM2 Green
Output 11 'define Robot Feedback LED => out11 => PWM2 Red
Output 12 'define Robot Feedback LED => out12 => Relay1 Red
Output 13 'define Robot Feedback LED => out13 => Relay1 Green
Output 14 'define Robot Feedback LED => out14 => Relay2 Red
Output 15 'define Robot Feedback LED => out15 => Relay2 Green
'---------- Initialize Inputs & Outputs --------------------------------------
Out7 = 1 'Basic Run LED on RC
Out8 = 0 'PWM1 LED - Green
Out9 = 0 'PWM1 LED - Red
Out10 = 0 'PWM2 LED - Green
Out11 = 0 'PWM2 LED - Red
Out12 = 0 'Relay1 LED - Red
Out13 = 0 'Relay1 LED - Green
Out14 = 0 'Relay2 LED - Red
Out15 = 0 'Relay2 LED - Green
I know this part controls the LEDs, but I’ve got two questions. First of all, what does “Output” do? Meaning, what does it mean when the code says, “Output 7”. And my second question, whats the relationship between “Output 7” and “Out7 = 1”? I take it 1 means the LED goes on and 0 means the LED is off, but how does it know that “Out7” sends to the “Basic Run LED”?
I am not the programmer on my team and I have never worked with BASIC stamps, just with Atmel AVRs, which are programmed in assembler, but most microcontrollers have a similar syntax, so here is my explanation:
On microcontrollers, most of the ports (except, for example, for the analog ones) can be either input or output. To tell the controller how you would like to access the port, whether as input or output, you have to define it in teh initialization statements. This can obviously be done by writing ‘Output’ followed by the port number. From there on, you cann access it by the internal aliases out[port number].
Take this as a temporay help, I bet that someone who knows the BASIC Stamp really well is going to post a reply sometime later this day.
Good luck!
You should download the Parallax manual (V2.0 is worth getting if you have the older manual – much clearer in my opinion).
Output is a Pbasic command that makes a pin an output on a Stamp2.
What it REALLY does is set a bit in the DIRS word.
There are 3 words that you should get to know if you are using Stamp2’s a lot (not so much if you only use them for FIRST, but it is still good to know).
DIRS is a word that sets the direction of data flow of the I/O pins 0-15
INS is a word that reflects the status of the voltage on the I/O pins 0-15.
OUTS is a word that determines the output value of the I/O pins, if DIRS is set to the output state (which I can’t recall whether it is a 1 or a 0 off the top of my head). Actually, the Stamp2 can only TRY to set the values to match OUTS, if something else is trying to make it something else, then it is a tug of war and the best man wins. With perhaps one of the battlers broken or wounded
Anyway, Output X sets bit X of DIRS to output status.
OUT1 is simply an alias for bit1 of OUTS. It is exactly the same as OUTS.bit1
*Originally posted by Joe Johnson *
**You should download the Parallax manual (V2.0 is worth getting if you have the older manual – much clearer in my opinion).
**
Ahh, thanks, thats the one bit of information I didn’t take a look at. Also thanks for your explanation, I see how it works now.