Photocell help
pollack
Posts: 9
i am currently trying to run a program that when the photocell senses diffrent light shades it gives out a value and makes a sound when it gets to that certain value. I have the values of the photocell working but all i need to do now is get the speaker to turn on when the value reaches the desired number.
Comments
' {$STAMP BS2}
time VAR Word
loop:
HIGH 2
PAUSE 100
RCTIME 2, 1, time
DEBUG HOME, "time = ", DEC5 time
IF time= 100 THEN sound
GOTO loop
sound:
FREQOUT 15, 1000, 1000
' {$STAMP BS2}
' {$PBASIC 2.5}
Photo·········· PIN···· 0
Spkr··········· PIN···· 1
AlarmLevel····· CON···· 500
Tone··········· CON···· 440
light·········· VAR···· Word
Main:
· GOSUB Get_Light
··DEBUG HOME, "Light = ", DEC light, CLREOL
· IF (light > AlarmLevel) THEN
··· FREQOUT Spkr, 100, Tone
· ENDIF
· GOTO Main
Get_Light:
· HIGH Photo
· PAUSE 5
· RCTIME Photo, 1, light
· RETURN
I've also attached a schematic that works with the Get_Light surbroutine.· Note that in your original program you use "LOOP" as a label name -- LOOP is now a PBASIC keyword so it shouldn't be used in this manner (you'll get an error if you enable 2.5 syntax).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
There's lots more you can do with photocells and speakers. Try the activities in chapters 7 and 8 of What's a Microcontroller. It's available for free download from www.parallax.com -> Downloads -> Stamps in Class Tutorials.
Regards, Andy
Post Edited (Andy Lindsay (Parallax)) : 6/3/2005 3:33:04 PM GMT