LED
nk_snyder
Posts: 7
Hey all,
I'm looking to control an LED using Max/MSP. Right now, I'm just looking to turn it on and off. I have a BOE but I'm basically just using a breadboard. Can someone point me in the right direction? I'm looking it up everywhere and can't find the answer.
~nks
I'm looking to control an LED using Max/MSP. Right now, I'm just looking to turn it on and off. I have a BOE but I'm basically just using a breadboard. Can someone point me in the right direction? I'm looking it up everywhere and can't find the answer.
~nks
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
The classic way to do this would be to use the BS2's "Programming Port", using:
SERIN 16, I9600, [noparse][[/noparse]DEC MyVal]
and
SEROUT 16, I9600, [noparse][[/noparse]DEC MyVal]
The "DEC MyVal" on the SERIN accepts a formatted decimal number followed by a Newline, and stores the result in the Word sized value Myval. Your BS2 program can then make decisions based on what this value is -- send a "1", CHR(10) and your program does one thing. Send a "0", CHR(10) and your program does something else.
The "I9600" above needs to be defined as a CON value, but varies based on the 'flavor' of BS2. See the "SERIN" command in the help file for more info. A 'plain' BS2 will use:
I9600 CON 16468 ' Inverted, 9600 baud
Now, if you did this, and attached an LED with a 470 Ohm resistor in series with it to, say, Pin Zero, the complete LED control program would be:
' {$STAMP BS2}
' {$PBASIC 2.5}
I9600 CON 16468
LEDPin CON 0
MyVal VAR Word
RESET:
SEROUT 16, I9600, [noparse][[/noparse]"Reset", CR] ' Provides evidence of brown-out reset, if any
LOW LEDPin ' I usually put my LED's to Vdd (+5). So "Low" turns ON the LED
MAIN: ' I always start my programs with a 'main' loop
· SERIN 16, I9600, [noparse][[/noparse]DEC MyVal]
· IF MyVal = 0 THEN
··· HIGH LEDPin ' Zero means 'off'. Set 'high' to turn off LED
· ELSE
··· LOW LEDPin ' 1 means "on". Set 'LOW' to turn ON LED
· ENDIF
· GOTO MAIN
Now, note that the above program will 'pend' (or 'wait') in the SERIN until it gets a value.· SERIN also has a 'timeout' parameter, which is what you want to use most times, but the above example should get you started.
Note also the BS2 hardware 'echoes' everything sent to it back to the sender, so you'll have to filter out the 'echo'.
Post Edited (allanlane5) : 10/3/2007 7:41:12 PM GMT
~nks