Compare a simple variable with an array

Hi all,

I want to capture a serial digital input and storate it like a byte, after this I want to compare it with a variable that I have.

My problem is:

I storate input in an array like this

uint8_t array[7];

for(i=0;i<8;i++)
array = digitalRead(pin);
After this I want to compare this array with a variable I have, something like this:
if(myvariable == array)
Serial.print("Same");
What I ask is, how I can do that in an efficient way?
- There is a library that can do that?
- Can I consider myvariable like an array and read a single bit?
- Can I storate input data in a variable without use an array?

for(i=0;i<8;i++)
 array = digitalRead(pin);

That won't work as it is. Let's see your real code that populates the array.

  • Can I consider myvariable like an array and read a single bit?
  • Can I storate input data in a variable without use an array?

Yes to both. Look at the bitRead() and bitWrite() functions

uint8_t array[7];

for(i=0;i<8;i++)
 array [i] = digitalRead(pin);

Write eight values to a seven element array?
I don't think so.

(Did you notice there how using code tags stopped the forum turning your code into italics?)