Hi now is working and thanks ALL for the big help.
My buttons are wired with a pull-up resistor:
so when the buttons are not pressed the register's bits are set to 1.
I saw another tutorial here:
http://www.ladyada.net/learn/arduino/lesson5.htmland they are using an input resistor of 100 Ohm.
Should I add that one as well or I can just use the internal pull up with the code by RoyK ?
The working code is now:
unsigned char old;
unsigned char check;
unsigned char diff;
void setup() {
int pin;
old=0;
for (pin=4; pin <= 6; ++pin) {
pinMode (pin, INPUT);
}
for (pin=8; pin <= 10; ++pin) {
pinMode (pin, OUTPUT);
digitalWrite (pin, LOW);
}
Serial.begin(9600);
test();
}
void test()
{
for (int pin=8; pin <= 10; ++pin) {
digitalWrite (pin, HIGH);
delay(500);
}
/*
PORTB = B00000000;
delay(500);
PORTB = B00000100;
delay(500);
PORTB = B00000010;
delay(500);
PORTB = B00000001;
*/
}
void allOn()
{
for (int pin=8; pin <= 13; ++pin) {
digitalWrite (pin, HIGH);
}
}
void allOff()
{
for (int pin=8; pin <= 13; ++pin) {
digitalWrite (pin, LOW);
}
}
void actuate()
{
PORTB = ~old>>4;
}
boolean checkstatus()
{
check=PIND & B01110000;
diff=check ^ old;
old=check;
if(diff==0)
return false;
else
return true;
}
void loop(){
//something has changed!
if(checkstatus())
{
Serial.println(old, BIN);
actuate();
//digitalWrite (13, HIGH);
delay(500);
}
else
{
//PORTB = B00000000;
//sample every 10 msec
delay(10);
}
}