help needed. Input/output states

Hi,

We are two students who are creating an physical electronic boardgame. But we don't have a lot of experience with arduino and electronics.

The way it works is there are little powercircuits on a tile, the player needs to connect the tiles together. Every tile is connected to a (digital) arduino port.

To get this working we needed to get the state of the port. It was working last week but isn't this week. Which is actually kind of strange and we don't know why.

Last week it was reading the right high and low states, this week it is just randomly doing something. And if it's working it just gives 3 times the right and 3 times the wrong state.

We have read about floating power but do not now a solution.

I hope you understand what we mean.

Could someone help us, please?
Thank you in advance for your time and advice!

Greetings,
Ingrid & Eveline

This is our code:
(We know it is not efficient)

void setup()
{
Serial.begin(9600);
pinMode(13, INPUT);
pinMode(12, INPUT);
pinMode(11, INPUT);

pinMode(10, INPUT);
pinMode(9, INPUT);
pinMode(8, INPUT);

pinMode(7, INPUT);
pinMode(6, INPUT);
pinMode(5, INPUT);
}

void loop()
{
int value13 = digitalRead(13);
int value12 = digitalRead(12);
int value11 = digitalRead(11);

int value10 = digitalRead(10);
int value9 = digitalRead(9);
int value8 = digitalRead(8);

int value7 = digitalRead(7);
int value6 = digitalRead(6);
int value5 = digitalRead(5);

Serial.print("poort 13 =");
Serial.println(value13, DEC);
Serial.print("poort 12 =");
Serial.println(value12, DEC);
Serial.print("poort 11 =");
Serial.print(value11, DEC);

Serial.println("");
Serial.print("poort 10 =");
Serial.print(value10, DEC);
Serial.print("poort 9 =");
Serial.print(value9, DEC);
Serial.print("poort 8 =");
Serial.print(value8, DEC);
Serial.println("");

Serial.print("poort 7 =");
Serial.print(value7, DEC);
Serial.print("poort 6 =");
Serial.print(value6, DEC);
Serial.print("poort 5 =");
Serial.print(value5, DEC);
Serial.println("");
delay(2000);
}

Could be pull-ups , or lack of.

Can I suggest you read about arrays?

We do have an example were we use arrays:

int Tegelpin = 0;
int Random = 5000;

// --- De nulwaarde array die moet controleren of een TegelPin op LOW of HIGH stond bij de vorige check
int Array_OudeWaarde[] = {
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW };

// --- De nulwaarde array die moet controleren of een TegelPin op LOW of HIGH stond bij de vorige check
int Array_NieuweWaarde[] = {
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, LOW,
LOW, LOW, LOW, LOW, LOW, HIGH };

// -------------------------De lengte van alle arrays tenzij specifiek vermeldt
int pinCount = 36;

void setup()
{
Serial.begin(9600);

// Eerst zetten we alle pins op output, geven ze de waarde LOW, en switchen daarna naar INPUT om later te kunnen readen
for(int Tegelpin=0; Tegelpin < pinCount; Tegelpin++)
{
/pinMode(Tegelpin+2, OUTPUT);/

pinMode(Tegelpin+2, INPUT);
//digitalWrite(Tegelpin+2, LOW);
}
}; //Setup

void loop()
{

// Begin met het doorlopen van de arrays
for(int CurrentTegelPin = 0; CurrentTegelPin < pinCount; CurrentTegelPin++)
{
Array_NieuweWaarde[CurrentTegelPin] = digitalRead(CurrentTegelPin+2);
//Serial.print(Array_NieuweWaarde[tegelpin]);
}

//Serial.println("");
delay(500);
};
//Loop

Does that lack of pull ups mean that our arduino is broken?
And if it is, how can it be fixed?

No, the pullups are built-in, but you're not using them.

On the other hand, you don't say how the tiles are wired.

What happens if you try this:

for(int Tegelpin=0; Tegelpin < pinCount; Tegelpin++)
 {
   pinMode(Tegelpin+2, INPUT);
   digitalWrite(Tegelpin+2, HIGH);
 }

in "setup()"?

There is no point in initialising your array "Array_NieuweWaarde", since you are overwriting it in "loop ()".
Are you going to assign the values in "Array_NieuweWaarde" to "Array_OudeWaarde" at some point?