# Array problems and others

``````int adpin = A0;// analog pin to read
int voltage = 0;// set to 0 the value of io input
int voltsarray; // create an array of 1023 to store
int count = 0;// integer for the voltsarray
int initialize = 0;
int arraycount = 0;
int maxlength = 1023;
int maxvoltage = 255

void setup()
{
Serial.begin(9600);
}
void loop()
{
{(voltsarray[arraycount] == initialize);arraycount++;
//zero the array
voltage == analogRead(adpin);// Read the voltage from the filter board
{if ((arraycount <= maxlength) && (voltage <= maxvoltage))   //1/4 of max advoltage is a low voltage lightning strike
{        voltsarray[arraycount] == voltage;//store advoltage into array
delay(100);         //temorary delay to read voltage into terminal
arraycount++;}            // increment the array counter.
Serial.println(arraycount};
}
``````

Im sure this is full of bugs as usual but I can’t find the problem.

In your words what is the difference between == and =
1023 int members in an array, how bytes of RAM will this use

In words, tell us what you are trying to accomplish.
Does a { require a } ?
When do you use braces?
One instruction per line.
Use CTRL T to format your sketches.

First the == question. I must have missed one. == stands for if a byte is equal to another byte. = is a bit test.
I am building a lightning detection system. I have a pc board that I designed which is a bandpass at 35khz. I got ahead of myself on the code but thought Id see if I could get it running. I need to first test the noise level at 35khz. The data from the ad is put into an array. Then I must test it to find what the noise floor is. This im not doing in the code. I am simply trying to test for a fourth of the maximum voltage (4 volts). This will indicate a distant lightning strike. In the code after I store the a/d values into the array I have to test for any levels above 1/4 of maximum. If there are any they go into the array until the array is full. That's what the code is supposed to do now. Then I will retest for 1/2 ad voltage and do the same thing. Then 3/4 , then full voltage. I wanted to use the comparator but Im using a max so the + comparator pin is not brought out to a header so Im forced to continually read the a/d and store the info for tests on the array. What I need to do either first or last like I said is to find the noise level because an active atmosphere ionizes the air causing the lowest level of the a/d to indicate the possibilities of violent weather in a 50 mile area.

stx38834:
First the == question. I must have missed one. == stands for if a byte is equal to another byte. = is a bit test.

No, on two counts.
"==" is a test for equality of expressions. "=" is an assignment.

== stands for if a byte is equal to another byte. = is a bit test.

= is assignment example:
int x = analogRead(A0);

== is for a test, means equal to, example:
if ( x == 512)
{
// do my stuff
}

If and integer is two bytes and you have 1024 elements that is 2048 bytes.
If you are using an UNO, how many bytes are left for your sketch?

I recommend you write some simple sketches before you tackle your project.
Study:

I know its a test for two expressions, the == but am still a bit confused with the simple = only that I know that it doesn't work comparing two statements containing integers and non integers but I did think it was byte wise. I have a book on Arduino that states that = does compare bits but Since things are not backward compatible I guess the book was wrong. I am having a bit of trouble with that. I type in an example even from the example sketches on this site and they don't work. Well whats wrong with the examples. Im not like many of you guys who have been programming in c and c++ all the time. This is very new to me. Only a couple of weeks so I beg your pardon on dumb questions but don't know where else to go with todays code. I have no idea what has been changed in the code from day to day and no way of finding out without asking questions. If it comes to an electronic problem maybe I can help. I am degreed in electronic engineering but haven't practiced it in about 10 years. This is a great hobby for anyone interested in programming and a good platform to work with. Also a fine group of gentlemen that take there time to answer my silly questions. Please bear with me as I learn.

I agree about the baby steps that's why Ive been trying to tackle this project section at a time where I can learn from my mistakes to make the next code better. Thanks for the input.

It would be considerably easier to read and understand your longer posts if you broke the text into paragraphs rather than jamming everything into a single block of text.

What do they say? The only dumb question is the question that isn't ask.

Thank you LarryD. I thought this was a place to ask questions about programming and not a place criticize. Sorry I offended anyone with posting to it. Nothing has even been said about the code I posted. Lots of laughs.

. I have a book on Arduino that states that = does compare bits but

Chuck the book away, because it is rubbish.

== is a test for equality
= is an assignment.

You may have gotten that concept mixed up with && and &, where && is a logical "and" operator, and & calculates the bit-wise "and" of two numbers.

Edit: actually, don't chuck the book away, because it is almost certainly correct, and it is your reading and comprehension skills that are rubbish. Instead of throwing it away, read it again, and pay attention this time.

``````int voltsarray;
``````

You clearly aren't running this on a Uno.

``````(voltsarray[arraycount] == initialize);
``````

The compiler won't complain, but did you miss an "if"?

Please use the IDE's auto format tool before posting your corrected code.

``````(voltsarray[arraycount] == initialize);arraycount++;
//zero the array
``````

Looks like you want to iterate though the array and set each element to 0. You need to put that in a ‘for’ loop.

And as others have said, = is an assignment, == is a comparison. Think of == as being similar to <= and >=.
<= is Less Than Or Equal
== is Equal (or Equal)

= is Greater Than Or Equal

You probably want to initialize your array either in Setup() if you only need to initialize it once, or put it in a separate function and call it when you need to reinitialize your array.

If you used a ‘for’ loop, you wouldn’t have to check for arraycount <= maxlength or manually increment it.

``````Serial.println(arraycount};
``````

That’s a typo. } should be )