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

Reley help

pollackpollack Posts: 9
edited 2005-06-20 13:24 in Learn with BlocklyProp
i just need some help on programming a reley . first i have this

' {$STAMP BS2}
' {$PBASIC 2.5}
Photo·········· PIN···· 0

lightLevel····· CON···· 200

light·········· VAR···· Word
Main:
· GOSUB Get_Light
· DEBUG HOME, "Light = ", DEC light, CLREOL
·· IF (light > lightLevel) THEN
· HIGH 0
· PAUSE 500
· LOW 0
· END if
· GOTO Main
Get_Light:
· HIGH 2
· PAUSE 5
· RCTIME 2, 1, light

what i am doing is hooking a reley up to a office lamp the thing is it works it turns on but it·clicks on and off. what i am attempting to do is make one of those lights that flick on when it gets dark in the room. so i just want some help in making stop·flashing. so when i put my hand·over the photocell i want it to turn on, it works when i do that but i just want·the light to stay until i remove my hand. i have to do this with the reley.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-20 13:24
    The program is cycling because you're turning the output on and then off -- so long as the light condition remains "dark" that will happen.· I made a small update to your program, and fixed a couple definitions to clarify things (you were mixing named constants and "magic numbers").


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

    CdS······· PIN····0
    Bulb······ PIN····1·········

    BulbOn···· CON··· 200
    BulbOff··· CON··· 150

    light······VAR····Word
    ·
    Main:
    · GOSUB Get_Light
    · DEBUG HOME, "Light = ", DEC light, CLREOL
    ··IF (light > BulbOn) THEN
    ··· HIGH Bulb
    ··· PAUSE 500
    ··· DO
    ····· GOSUB·Get_Light
    ····LOOP UNTIL (light < BulbOff)
    ··· LOW Bulb
    ··ENDIF
    · GOTO Main
    ·
    Get_Light:
    · HIGH·CdS
    · PAUSE 5
    · RCTIME CdS, 1, light
    · RETURN

    Notice the span between BulbOn and BulbOff -- this gives the program a bit of hysteresis so that·the bulb·doesn't osciallate when the light level is right around the threshold.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.