Shop OBEX P1 Docs P2 Docs Learn Events
Rc delay program not returning — Parallax Forums

Rc delay program not returning

lockadoclockadoc Posts: 115
edited 2009-10-26 00:26 in Propeller 1
I'm trying to make the photoresistor sense dusk and start a method,than when is senses dawn to stop the method.
also how do I make the method average out the photoresitor's·readings·so that headlights or clouds don't make it respond.

Right now the method will take readings then run the method when it senses dusk and stays with that method .I tried a DO WHILE
but that did no work.

thanks BillS

Comments

  • KyeKye Posts: 2,200
    edited 2009-10-25 04:57
    Everything in the code you posted look fine. What's in:

    LifeWithCog :"LifeWithCog" ' Heartbeat
    display3: "display3" ' light show

    Please post them also. If you want to average a bunch of values then just keep adding them together for like 100 times and then divide by 100 to get the average. Since you want to spread the measurements out over time I would take alot of samples then to average with or make your program run slower.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • lockadoclockadoc Posts: 115
    edited 2009-10-25 06:31
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-25 07:30
    Hello Billy,

    it's not clear to me how your program should work. You are just talking of run method ... then ... method... without NAMING it.

    SPIN supports structured programming and you should use it. Here this means to put that part of the code
    that is measuring the RC Decay into its OWN PUB and that this code it gives back a return-value

    there are two approaches to make a program different tasks
    1) the basic structure of your code could follow this:

    there is a main-LOOP and all things that have to be done repeatedly
    like check for dusk/dawn switch light pattern etc.
    are called from this main-LOOP after each SINGLE call

    For example this means NO repeat INSIDE of method display


    2) spend a cog on each task and have software-switches that turn on/off actions
    the software switches are simple variables and you check them for value "0" do nothing or value "1" do it

    f.e. for method display this would mean

    VAR
      long SwitchLights
    
    PUB Set_State_Of_SwitchLights (State)
      SwitchLights
          
    PUB Display3
    
      dira[noparse][[/noparse]0..7]~~
    
      repeat
        if SwitchLights == 1
          outa[noparse][[/noparse]0..7] := %10001000
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %11001100
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %11101110
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %11111111
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %11101110
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %11001100
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %10001000
          waitcnt(clkfreq/4 + cnt) 
          outa[noparse][[/noparse]0..7] := %00000000
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %00011000
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %00111100
          waitcnt(clkfreq/4 + cnt)
          outa[noparse][[/noparse]0..7] := %01111110
          waitcnt(clkfreq/4 + cnt)
    



    The main-cog checks for dusk or dawn and depending on dusk or dawn

    it calls the method Set_State_Of_SwitchLights(0) or Set_State_Of_SwitchLights(1)

    As the method display3 is in its own object file You need the second method Set_State_Of_SwitchLights()
    because you can't access variable across objects. If this explaining is above your head
    you should interrupt your project and re-read the manual or the PE--kit-labs about objects

    by the way
    "Display3" is a only half self-explaining name. What is it "displaying" ??? Text ? Decimal value of photoresistor ?

    something like "Switch_BitPattern_IO0_7_OnOff_4Hz" would say almost EVERYTHING about what is happening inside this method


    For the problem of headlights different ideas:

    make the sensor look into a direction where it cannot be blinded by headlights
    focus the sight to a tunnel by putting the sensor into a tube

    or think about what differences can be detected between sunlight goes down and it gets slowly dark
    and headlights of cars passing by ?

    best regards

    Stefan

    Post Edited (StefanL38) : 10/25/2009 8:08:50 AM GMT
  • lockadoclockadoc Posts: 115
    edited 2009-10-26 00:26
    Ok I get it now

    make the main method do the repeats not the called method.

    thanks BillyS
Sign In or Register to comment.