Problems with Programming
Krishen
Posts: 8
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.
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
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
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.
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!
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.
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
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
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 Savage
Parallax Tech Support