Is there an easier way to write code to read multiple digital pins than this?


i'm making midi controller , need read lots of buttons... there easier way write code read multiple digital pins , return number of 1 goes high...??

easier this...

  if (!digitalread(buttonpin1[0]) == high) {
    count = 1;
  }
  else if (!digitalread(buttonpin1[1]) == high) {
    count = 2;
    }
    else if (!digitalread(buttonpin1[2]) == high) {
    count = 3;
    }

....etc


i have lot of button , new learning arduino... can't figure out if there better way simplify this.

any appreciated. :)

the first thing comes mind loop read through buttonpin array.  value of count can derived loop variable , if break loop when pin found high same effect if/else , stop reading pins @ first 1 found high


Arduino Forum > Using Arduino > Programming Questions > Is there an easier way to write code to read multiple digital pins than this?


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'