Shop OBEX P1 Docs P2 Docs Learn Events
LED — Parallax Forums

LED

nk_snydernk_snyder Posts: 7
edited 2007-10-03 21:05 in Learn with BlocklyProp
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

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-03 18:22
    Sorry, what's a "Max/MSP" again? Where is there a website which mentions it? Is it a Parallax product?
  • nk_snydernk_snyder Posts: 7
    edited 2007-10-03 18:24
    It's a visual programming enviroment. I'm trying to get it to talk to BS2, but fight I want to try to toggle an LED on the breadboard on the BOE
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-03 18:29
    And the website that refers to this tool is?
  • nk_snydernk_snyder Posts: 7
    edited 2007-10-03 18:33
    http://www.cycling74.com/ <--- that's the website of the company that makes Max/MSP. I think I made the mistake of posting here rather than on their forums rolleyes.gif
  • dandreaedandreae Posts: 1,375
    edited 2007-10-03 18:41
    Are you able to communicate serially through your software?·· If so, you can send over characters that can be interpreted by the BASIC Stamp which can control I/O pins.



    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • nk_snydernk_snyder Posts: 7
    edited 2007-10-03 19:19
    i'm able to connect the a serial cable to my computer and send commands to the BS2. I'm almost done the tutorials that came with the BS2.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-03 19:36
    OK, so Max/MSP is a programming environment for the PC, that helps you play music on the PC. And you want to use the BS2 as a 'slave' processor to do stuff in real-time (like light an LED, for an initial simple example).

    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
  • nk_snydernk_snyder Posts: 7
    edited 2007-10-03 21:05
    thanks for the help. I don't quite understand any of that right now...but I'm sure it will help at some point in the future

    ~nks
Sign In or Register to comment.