button array status poll via PORTD


hi guys have arduino 2009 board atmega 328 , it's configured in way:
pins ,4,5,6 connected switch buttons (in total 3)
pins 7 connected led

i want poll status of buttons , if change detected update led status.
i wrote simple code not working (the led never switches on), never used portd register before guess wrong data type.


byte old;
int buttons[6];
void setup() {
 
       int pin;
       old=0;
       for (pin=1; pin <= 6; ++pin) {
           pinmode (pin, input);
       }

       for (pin=7; pin <= 13; ++pin) {
           pinmode (pin, output);
           digitalwrite (pin, high);
       }
}
void allon()
{
      (int pin=8; pin <= 13; ++pin) {
           digitalwrite (pin, high);
       }
}

void alloff()
{
        (int pin=8; pin <= 13; ++pin) {
           digitalwrite (pin, low);
       }
}

boolean output()
{

}
boolean check()
{
 byte check=portd & b01110000;
 byte diff=check ^ old;
 old=check;
 if(diff>0)
   return true;
 else
   return false;
   
}

void loop(){

 //something has changed!
 if(check())
 {
 output();
 digitalwrite (13, high);
 delay(500);
 }
 else
 {
    digitalwrite (13, low);
 //sample every 10 msec
 delay(10);
 }
}

how have switches wired? between input pins , what?
if wired inputs ground , don't have external pullups turn on internal ones writing each of input pins high.

int pin;
      old=0;
      (pin=1; pin <= 6; ++pin) {
          pinmode (pin, input);
          digitalwrite(pin, high);    // add this
      }


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > button array status poll via PORTD


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums