Unable to read write to array

I am trying to learn how to read/write to an array. The onboard led should change its blink rate when I either ground pin 2, or connect to +5v. Unfortunately, the led remains off. Any suggestions how to fix the code will be appreciated. I have been working on it a few days now without success.

const int ledPin = 13; // onboard LED const int hallPin = 2;

byte test[3][8] {{0, 0, 0, 0, 0, 0, 1, 1}, {0, 0, 1, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1}};

void setup()
{
pinMode(ledPin,OUTPUT);
pinMode(hallPin,INPUT);
}

void loop()
{

if (hallPin == HIGH)
{

test[2][2] = 1;
digitalWrite(ledPin, test[2][2]);
delay(200);

test[2][2] = 0;
digitalWrite(ledPin, test[2][2]);
delay(200);
}

else if (hallPin == LOW)
{
test[2][2] = 0;
digitalWrite(ledPin, test[2][2]);
delay(100);

test[2][2] = 1;
digitalWrite(ledPin, test[2][2]);
delay(500);
}
}

For starters, you must read the state of the hall pin:

...
if (digitalRead(hallPin) == HIGH)
{
 //High
}
else
{
 //Low
}
...

'hallPin' is 2 so it is never going to be == HIGH (== 1) or == LOW (== 0). As shown above, you need 'digitalRead(hallPin)' to read the input pin.

When you just playing with arrays and indexing to see what's what and what's where, it will make your experiments more revealing if you use different numbers, so ledPin[2][3] for example.

a7

Thanks. Much appreciated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.