Hi Carsten, good job!
if (digitalRead(4)==HIGH and dir==1)
The C language uses && for a logical and. I have never seen the word and used instead of &&. Have you seen this documented somewhere? I guess it works if your sketch runs ok
Coding style is very much a personal thing, but FWIW here are some coding suggestions
Your code will be easier to understand if you use #defines for constants. For example:
pinMode(5, INPUT);
if (digitalRead(4)==HIGH and dir==1)
could be:
#define LEFT 1
#define leftPin 4
pinMode(leftPin, INPUT);
if (digitalRead(leftPin)==HIGH && dir== LEFT) // checks mercury switch
It wont make a big difference, but there are some expressions you can simplify, for example you can replace:
if (pattern & (1<<i)) {
digitalWrite(myPins[i],HIGH);
}
else {
// turn off the LED at location (x,y)
digitalWrite(myPins[i],LOW);
}
with:
digitalWrite(myPins[i], pattern & (1<<i) ); // Set the LED state to match the bit at position i
but stick with what you feel most comfortable with.
Have fun!