LDR (Light Dependent Resistor -> FC V8

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times

Re: LDR (Light Dependent Resistor -> FC V8

Post by Frank607 »

Hi,

I have done it by this way. I will use CO, C1, C2 and C3 for PWM 1 to 4. The mosfets are also connected to these PIN's. This works great now with one mosfet on C0.
2023-07-24_09-06-05.jpg
2023-07-24_09-06-05.jpg (75.57 KiB) Viewed 10195 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: LDR (Light Dependent Resistor -> FC V8

Post by chipfryer27 »

Hi

Good hear you are getting there.

Regards

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times

Re: LDR (Light Dependent Resistor -> FC V8

Post by Frank607 »

Many thanks for all the help! I appreciate this very much.

There is one more thing I would like to see in the flowchart. I can't think of this.

It would be nice if the LDR could be read once per minute and the average value calculated within a period of, say, five minutes. This value then goes to the variable ADCValue.

This is to prevent problems if, for example, five cars pass by when it is dark.

Of course, the LDR can be read once every five minutes, but an average of this is better.

I hope you understand what I mean.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: LDR (Light Dependent Resistor -> FC V8

Post by chipfryer27 »

Hi

A few ways to do it. One way would be to set an interrupt to create a "seconds" counter.

I you set up an Interrupt on Timer0 (any, but not timer 2 as that is being used) and have this quite slow, say for example 60.xxHz, this would interrupt approximately sixty times per second and jump to a predefined Macro. If interrupt frequency was 75Hz then you would interrupt 75 times a second and so on.

This Macro increments a counter variable (e.g. x=x+1)
When x=>60 (or whatever interrupt frequency is) then increment another variable (e.g. seconds) seconds=seconds+1 and then set x back to zero

Now you have the variable "seconds" incrementing every second (or thereabouts).

When seconds = 60/120/180/240/300 you take an ADC reading and add it to a variable say ADCavg. After you have added your fifth reading (when seconds = 300) divide ADCavg by five to give you the average, and set seconds back to zero. Don't forget to set ADCavg back to zero too once you use it.

I'm sure you get the idea.

Do note that the chip you are using can probably interrupt at 0.015Hz (approximately once a minute) or lower (longer). Have a play in the Interrupt properties. You don't really need exact intervals so experiment to suit :)

Regards

Post Reply