Rc delay program not returning
lockadoc
Posts: 115
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
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
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,
BillS
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
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
make the main method do the repeats not the called method.
thanks BillyS