Shop OBEX P1 Docs P2 Docs Learn Events
Problems with Programming — Parallax Forums

Problems with Programming

KrishenKrishen Posts: 8
edited 2008-05-21 21:28 in BASIC Stamp
Let me preface this by stating that I have close to no idea what I'm doing.I'm attempting to replicate the project done here (http://forums.parallax.com/attachment.php?attachmentid=50010).
I copied the programming into the BASIC Stamp Editor, word for word, but it's not working.

' {$STAMP BS2}
' {$PBASIC 2.5}

'This program will monitor the sound falling on a microphone, toggling a number of lights whenever a very loud sound is heard.'

symbol pcell = PIN0
symbol pcellpin = 0
symbol light1 = PIN1
symbol light2 = PIN2
symbol light3 = PIN3
symbol scale = 200

OUTPUT 1
OUTPUT 2
OUTPUT 3

read_pcell:
pot pcellpin,scale,B2
DEBUG B2
GOTO read_pcell

is_light1_on:
IF B2>200 THEN light1_on

light1_off:
light1=0
GOTO is_light2_on

light1_on:
light1=1

is_light2_on:
IF B2>100 THEN light2_on

light2_off:
light2=0
GOTO is_light3_on

light2_on:
light2=1

is_light3_on:
IF B2>40 THEN light3_on

light3_off:
light3=0
GOTO is_light4_on

light3_on:
light3=1
is_light4_on:
GOTO read_pcell

I clicked the play button to run the program, and it says that "The Label is missing ':'", with the first symbol, at the beginning, highlighted.
Any help with that problem and any others you may see (I'm sure there are a few)·would be greatly appreciated.

Many thanks in advance.

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-29 18:30
    Ah. Well "Symbol" is a BS1-ism.

    So the program for a BS2 should be more like:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'This program will monitor the sound falling on a microphone,
    ' toggling a number of lights whenever a very loud sound is heard.'
    'SYMBOL pcell = PIN0
    'SYMBOL pcellpin = 0
    'SYMBOL light1 = PIN1
    'SYMBOL light2 = PIN2
    'SYMBOL light3 = PIN3
    'SYMBOL scale = 200

    PCell··· PIN 0
    PCellPin CON 0
    Light1·· PIN 1
    Light2·· PIN 2
    Light3·· PIN 3
    Scale··· CON 200

    OUTPUT 1
    OUTPUT 2
    OUTPUT 3

    read_pcell:
    · RCTIME pcellpin,scale,B2· ' This needs to be fixed to read the capacitor properly...
    · DEBUG B2
    · GOTO read_pcell

    is_light1_on:
    · IF B2>200 THEN light1_on

    light1_off:
    · light1=0
    · GOTO is_light2_on

    light1_on:
    · light1=1

    is_light2_on:
    · IF B2>100 THEN light2_on
    light2_off:
    · light2=0
    · GOTO is_light3_on

    light2_on:
    · light2=1
    is_light3_on:
    · IF B2>40 THEN light3_on
    light3_off:
    · light3=0
    · GOTO is_light4_on

    light3_on:
    light3=1
    is_light4_on:
    GOTO read_pcell

    Post Edited (allanlane5) : 4/29/2008 6:35:12 PM GMT
  • KrishenKrishen Posts: 8
    edited 2008-04-29 18:34
    Beautiful, thanks. It works.

    What do you mean by the 'this needs to be fixed' bit? Keep in mind my lack of experience (and I'm not speaking in relative terms.)

    Thanks again, I really appreciate it.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-29 23:49
    It WORKED? That's amazing.

    The "POT" command on the BS1 reads a charged capacitor. The "RCTIME" command is used for this on the BS2 -- but usually you're trying to read an unknown capacitance, so you 'charge' it with an earlier "HIGH" command, then use RCTIME to measure the decay rate.

    Apparently, for your application, the Microphone would charge the capacitor, so the RCTIME by itself was sufficient. I wasn't sure that would work. But apparently it does, so contratulations!
  • KrishenKrishen Posts: 8
    edited 2008-04-30 00:22
    Let me elaborate =)

    My, uh, test, was to click run and see if it came up with any errors. Allanlane5, could you perhaps explain the syntax with the RCTIME command?

    Also, I don't think the pot command is in your section of the code, but I assume you know that.

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-30 00:31
    Please download the Stamp Basic Syntax and Reference Manual and read the chapter on the RCTIME statement.· It goes into much detail on the syntax and semantics of the statement.· Go to the main Parallax web page, select the Resources tab, then choose Downloads.· You'll see a link for Basic Stamp Documentation and you'll find the manual there.

    Allanlane5's comment was probably a reference to the fact that you have to adjust the R and C values to get the time range you want.· There's a good description of the use of the RCTIME statement for analog to digital conversion here·http://www.emesystems.com in the page labelled "app-notes"




    Post Edited (Mike Green) : 4/30/2008 12:36:56 AM GMT
  • KrishenKrishen Posts: 8
    edited 2008-04-30 00:40
    Thanks, I appreciate your help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-05-20 18:59
    Krishen,

    You have posted this question in 4 threads in multiple forums. This is against the forum guidelines. Two of the four threads have been removed. Please post follow-up questions in existing threads in the future.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • KrishenKrishen Posts: 8
    edited 2008-05-21 15:27
    Okay, sorry about that. I'll post solely in this thread in the future.

    Questions:

    Is the PULSIN command going to work properly?
    Also: What does B2 mean, as part of that same command? From what I understand of the syntax, you need to specify the port and the amount of time. Pcellpin is the port, and scale is the amount of time, right? Or do those two commands make up the interval for the time, and B2 is the port?

    PCell PIN 0
    PCellPin CON 0
    Light1 PIN 1
    Light2 PIN 2
    Light3 PIN 3
    Scale CON 200

    OUTPUT 1
    OUTPUT 2
    OUTPUT 3

    read_pcell:
    PULSIN pcellpin,scale,B2 ' This might need to be fixed to read the capacitor properly.
    DEBUG B2
    GOTO read_pcell

    is_light1_on:
    IF B2>200 THEN light1_on

    light1_off:
    light1=0
    GOTO is_light2_on

    light1_on:
    light1=1

    is_light2_on:
    IF B2>100 THEN light2_on
    light2_off:
    light2=0
    GOTO is_light3_on

    light2_on:
    light2=1
    is_light3_on:
    IF B2>40 THEN light3_on
    light3_off:
    light3=0
    GOTO is_light4_on

    light3_on:
    light3=1
    is_light4_on:
    GOTO read_pcell

    ' End of code.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-05-21 21:28
    B2 is a register in the BASIC Stamp used to store variables. You really should declare your variables with labels instead of referring to a specific register.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.