Shop OBEX P1 Docs P2 Docs Learn Events
Photocell help — Parallax Forums

Photocell help

pollackpollack Posts: 9
edited 2005-06-03 15:28 in Learn with BlocklyProp
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

  • pollackpollack Posts: 9
    edited 2005-06-03 13:20
    here is what i have so far

    ' {$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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-03 13:38
    With PBASIC 2.5 you can code your program quite easily:

    ' {$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
    466 x 237 - 6K
  • edited 2005-06-03 15:28
    Pollack,

    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
Sign In or Register to comment.