In the old school Basic, you could define a numebr of variables; arrays. The command was DIM A (100).
This command defined 100 variables (A1, A2,A3....A100).
Is this possible with the Arduino?
Arduino code is written in C++. Google "C++ array" and you will find plenty of info and tutorials on the very subject.
Is this possible with the Arduino?
Of course:
int A[100];
Hi PaulS, I will try that:) Thanks!
This command defined 100 variables (A1, A2,A3....A100).
No, it didn't.
AWOL; yes it did.
PaulS; doesn't work..
It must've been a peculiar dialect of BASIC then.
A1 is a completely different variable to A(1)
@PaulS; mistyped it, it seems to wrk. Will try it, thanks!
Study this simple example and try to figure out what it does before you run it.
void setup() {
int i;
int a[100];
Serial.begin(9600);
for (i = 0; i < 100; i++)
a[i] = i * i;
for (i = 1; i < 100; i++) {
Serial.print(" ");
if (i % 10 == 0) {
Serial.println(a[i]);
} else {
Serial.print(a[i]);
}
}
}
void loop() {
}
It may help you understand the difference between Basic- and C-style arrays.
Thanks all.
Now the int [170] works. Now it is a challenge to get the lowest value from those analoge readings. Tryed min but doesn't work.
You can be assured "min" works as specified.
AWOL:
You can be assured "min" works as specified.
(My emphasis).... and therein, as always, lies the rub.
@ AWOl; ofcourse. That is why it doesn't help me.
Well, change "min" so it does help you - you've got the source.
The minimum value of any two elements of the array will eliminate one element from contention. Do that often enough, and only one value will remain, and it will be the smallest one.
AWOL
I don't see the point of your post. It doesn't help. Maybe it makes you feel better but it is a waste of bytes.
PaulS
Yes, I know. The thing is, the minimum value x[a], needs to point to a postion of a servo where that value was read.
My post was intended to provoke you into explaining your belief that "min" doesn't work ( or how, in BASIC, "DIM A(100)" somehow creates a variable called A1), and maybe post some code so that you could get some help.
Looks like I failed.
Ho-hum.
The thing is, the minimum value x[a], needs to point to a postion of a servo where that value was read.
Are you saving the servo angles corresponding to the x[a] values ?
If only we could see your program .....
Yes, I know. The thing is, the minimum value x[a], needs to point to a postion of a servo where that value was read.
Are you looking for the minimum value in the array, or the location where the minimum value appears, or both?
Regardless, assume that the minimum value is at position 0. Compare that minimum value to the other positions, using a for loop. If the value at position n is less than the current minimum, replace the current minimum with the new lower value and, if important, replace the index to the minimum position with the index to the current position. When the for loop ends, you'll know the minimum value and the position where that value occurred.
The servo is going from 1 tot 171 degrees. While doing that, it is measuring light intensity. So is this case for eg. x[1] is reading a value of 721, x[2] 786, x[3] 210 etc So the minimum is not nessesarily at the beginning. It can be everywhere.
x[1]......... x[171] with the values are stored.
We know that the value of x[1] is measured while servo had postion 1. So if i can get the minimum, by camparison, I gen get the position.