Digital Reading pins set up as an array

I have my pins set up as an array if I want to digitally read all the pins in the array and store it in a new array with only '1' and '0' how would I do this?

just guessing (since you did not post any CODE!) but something like this maybe…

//////////////////////////////////////////////////////////////////////////////////////

uint8_t pin_num[num_of_pins]; //8-bit wide unsigned integer array
bool pin_read[num_of_pins]; //boolean type array. stores either 0 or 1 (number)

for(uint8_t i=0; i< num_of_pins; ++i){
}

//////////////////////////////////////////////////////////////////////////////////////

You have to understand the following points:

1. Say, the DPin-2 is configured to work as input with internal pull-up resistor enabled. Now, we connect a button (K1) between DPin-2 and GND. Let us close the button (K1) and then perform a digitalRead(2); operation. According to Arduino Reference Manual, the function/macro will return LOW.

2. The numerical value of LOW is minimum 0x00 (to me; 00000000 in binary). Do you want to save this value in a location of an array? The size of an element/member/item of the array should be 8-bit (byte). You cannot really store 0 (1-bit value) for LOW and 1 (1-bit value) for HIGH.

3. Therefore, the array declaration would be:
byte myData[5]; //for 5 DPins

clamthief:
I have my pins set up as an array if I want to digitally read all the pins in the array
and store it in a new array with only ‘1’ and ‘0’ how would I do this?

To get ‘0’ or ‘1’ (which are char constants) in the array you could use something like

``````uint8_t pin_num[num_of_pins];

for(uint8_t i=0; i< num_of_pins; ++i){
}
``````

store it in a new array with only '1' and '0'

Do you actually mean '0' and '1' (characters) or do you mean 0 and 1 (integers) ?

clamthief:
I have my pins set up as an array if I want to digitally read all the pins in the array and store it in a new array with only '1' and '0' how would I do this?

What have you wanted to mean by these literals: '1' and '0'?

Does '1' refer to an alphabet of the English Language character set? Is it the numeral character 1? If so, then the declaration to save it into computer memory would be: char x = '1';.

Does '1' refer to one of the symbols of the 10-symbol based Decimal Number System? Is it the symbol 1? If so, then the declaration to save it into computer memory would be: byte x = 1;.

I’m just using 1’s and 0’s to add up all the elements and easily figure out how many pins have current running through them. Here’s a code I tried to use, but I keep getting nothing. I need integers.

``````void loop() {
Vector<int> blocks;
bool B[grid];
int sum_of_blocks;
int C;

if(T == 1){
A = area[random(0,10)];
T = 0;
}else if(T == 0){

int j;
for(j=0; j <= grid; j++){
};

int l;
for (int m= grid ; m > 0; --m){ // Adds all elements in the blocks vector
sum_of_blocks += B[m-1];
};

C = sum_of_blocks;
if(C == A){ // Checks if block vector sum is == to random generated area to restart the program with a new A
T = 1;
lcd.clear();
}else{
T = 0;
}
``````

clamthief:
I'm just using 1's and 0's to add up all the elements and easily figure out how many pins have current running through them.

That says to me you don't need to know which pins, just how many. So you don't need to store the results of each digitalRead in an array, you just need to increment a counter, or not.

pins have current running through them.

But that's a bit of a loose statement; do you just mean if a pin is high or low? You will need to have a pull down or pull up resistor on each pin to ensure relaible reads, so you will need to account for the natural state of the pin. With a pull down, the pin is normally low and high when pressed. With a pull up, it's naturally high and low when pressed.

I need to know if a hall effect sensor switch is open or closed. I would like all the pins to be in a default 0 state each time it loops

clamthief:
I need to know if a hall effect sensor switch is open or closed. I would like all the pins to be in a default 0 state each time it loops

If the pin is connected to the output of the hall sensor, how can it be in a default state?- an input pin will surely reflect the state of the sensor's output.

The only hall sensor I've used is an Allegro 1106 which is active low. If yours is active low, pinMode its pin as INPUT_PULLUP and increment your counter when it's low. (That is, assuming what you said earlier is that you don't need to know which sensors are active, just how many?)