Go Down

Topic: Potted plant watering system. (Involves water pumps.) (Read 11 times) previous topic - next topic

lost_and_confused

AWOL,

Thanks very much for the effort of the reply.

My learning curve:
(kind of, and worded around this sketch)

I want inputs and outputs.  Originally I called them input_1, input_2, input_3 and so on.   And output_0, output_1, output_2 and so on.

To save the the repetitive nature of typing near exact lines I did a loop around it.
So from other things I have seen, I made them look like:
input_[0], input_[1], and so on.

But it didn't work and I was pointed in the direction of the example sketch on how to do arrays.

I mis-understood what was initially explained/read and changed it to:
input[0], input[1] and so on.  No   _

But what I missed was the 'Pin' included in the definition.

So I changed it to things like:
inputPin[0], inputPin[1], etc.

That then worked better but I still don't understand what is "really happening".

Again:  I am only doing this to save a lot of typing and being able to use an index (in this case the ubiquitous letter i) between routines so the next function can get the required values easily.


So now I shall try to work through what you mentioned:

#define sensorPins[0] 14
#define sensorPins[1] 15

That is where I want to tell the system I want these pins (the last number) to be inputs called sensorPins0, sensorPins1, sesnsorPins2, etc.
Ok, some parts of that may be deleted/negated on compilation.

With the status quo, in the setup() I had:
   pinMode(sensor[0],INPUT);

and it was mentioned that this won't work.
Granted I don't know what I am doing.   But don't you just love my enthusiasum - how ever you spell it?

So....  (digging myself further towards stupidity) I try "completing" the name so it matches the name declared in the GLOBAL part and have this:

    pinMode(sensorPins[0],INPUT);
    pinMode(sensorPins[1],INPUT);

Obviously that doesn't work - well hindsight for me - but I am not see what is going on.

In the big picture I hope you can see what I am TRYING to do, but am obviously failing at getting done.

I guess it wouldn't kill me to do the whole thing the long way and get it working initially then try to optimise it down to something like this structure style.

const byte sensorPins [] = { 14, 15 etc

Is probably what I am wanting to do, but I don't know what it means.

Yes:  My problem.  I need to do more leg work and maybe read.  I shall.  But again I shall mention I don't know the entire vocabulary and so don't know for what commands to search to achieve my desired result.


So indulge me about how what I shall call "Arrays" work.
Which I am guessing are things like:
int My_variable[10]
means there are 10 "My_variable" variables. 
My_variable1, My_variable2, My_variable3, My_variable4, and so on.

This way it would save me manually making them all, and being able to index them with something like:
i = 3
xx = My_variable

would make xx equal to what is My_variable3

Ok, I may have the syntax slightly wrong in that it is:
My_variable[3].

I don't know.

I'd better stop now because I think I have dug myself in deep enough for now.

AWOL

#21
Jul 18, 2012, 10:23 am Last Edit: Jul 18, 2012, 10:29 am by AWOL Reason: 1
Code: [Select]
#define sensorPins[0] 14
No.
As I said, I'm not even sure what that will do.

Use
Code: [Select]
const byte sensorPins [6] = {14, 15, .. etc}; instead.

This defines an array of bytes (8 bit unsigned ) of constants, and assigns the value 14 to index zero, 15 to index one and so on.
If the list on the right (the "{14, 15 }" bit) does not contain as many entries as specified on the left hand side of the assignment (the "[6]" bit), then the array is padded to the end with zeroes.
The indices of this array run from zero to five inclusive.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

lost_and_confused

(I'm going to have to dig up my other Arduino and my prototype board and build this so I can see what is going on.)

Thanks though.

AWOL

#23
Jul 18, 2012, 10:36 am Last Edit: Jul 18, 2012, 10:39 am by AWOL Reason: 1
Code: [Select]
int sensor_delay(int x)
It looks to me like this function doesn't return anything, so it would be better described as
Code: [Select]
void sensor_delay(int x)
(it would also be better if you thought of a better name than "x")

It is also confusing me why you're assigning the value of "x" to the variable "i", instead of simply using "x" throughout this function.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

lost_and_confused

Well,

sensor_delay(i)

The "index" i is sent to the function.

From that, the "run time" is derived.
(    TTG = sol_run_time;  )

While the value of time_up > 0 it loops.

Then it calls the "timer" routine with TTG.

"Timer" gets the TTG value and counts down that many minutes.
The remaining value is returned and if not zero, it aborts the loop.

I just noticed that I goofed in line 197 in that it should be time_up and not TTG.

In that loop, it looks at the sensor input for that pot and checks it hasn't become active/exceeded/what ever the defined value for THAT pot - for now it is all just set to a nominal value.


Am I making sense?

Go Up