curtain controller

davidwf

Senior Member
Being new to PICs (and now this excellent forum) but an old hand at electronics I want to replace my curtains / lights controller comprising of 8 i/c's and a bucketful of components and relays with a PIC and some software....so far so good.

I need a program to read the light level from an LDR (I should be able to manage that), if below a certain value wait for a few minutes to prevent operation by clouds etc., then if still low activate an output for about 2 seconds to operate the switch of a commercial RF remote controlled lights system, then after a further few minutes delay activate another output for a few seconds to close my motorised curtains.

The curtains remain closed until it is daylight again and a separate stand alone timer currently turns the lights off at a set time, I would prefer to keep this for simplicity rather than incorporate a real time clock module.

Like I said I am completely new to programming and I can't see how to make the main program run repeatedly (checking light level) and then also driving a relay or similar output.
Any guidance appreciated and I hereby promise to publish the completed circuit whan I have done it....and I WILL do it !

Thanks in anticipation
 

papaof2

Senior Member
Pseudocode framework---

main:
check_light_level 'use ADC to read LDR

if light_level less than minimum_daylight_level then
do dark_work_here
end if

if light_level greater than minimum_daylight_level then
do light_work_here
end if

goto main 'keep checking

You may find better examples already on the forum...

John
 
Last edited:

Dippy

Moderator
David,

Look at Papa's suggestion.
Look at the basic Manual (Maual 2) and study the list of commands.

See how Papa has written a pseudo-Basic-English code where he has listed out the tasks to be done.
You should adopt a similar approach for all your programming.
Write out a list of tasks that you want to be done. Include branches where decisions have to be made (e.g. IF something > something-else then do something-interesting).
You will build up a flow chart.

You can break each section down into a list of commands in Basic.
i.e. fill in the details and translate to BASIC.

Many people have the sections of code as subroutines, some just write a big pile of code.
Subroutines are neater and you can cut'n'paste into future code if needed.
Keep it neat so that you can read / understand / change it in 3 months time - or in my case about 2 minutes time.

(Remember, it is very trendy to sneer at the 'GoTo' statement. If you have any boring programmers in your Pub remember to scoff loudly if you hear someone say 'Go To' unless they are referring to the toilet, in which case, tell them where it is quickly. Seriously though, one or two Gotos are fine. Too many and you can have spaghetti code.)
 
Top