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.
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
Post a Comment