hi everybody,
I’m working on a project where i have a lots of button.
so i create my own variable like this one:
//Buttons-----------------------------------------
typedef struct Button Button;
struct Button
{
boolean curState;//1 is ON, 0 is OFF
boolean prevState;
boolean pressed;
boolean justPressed;
boolean justRelease;
boolean hold;// 1 is holding
byte counter;//count number of push on the button
unsigned long curTime;
};
the thing is that i have to initialise more than 32 buttons.
How can i create a function to simplify this code?
//backward button-------------------------------
backBtn.justRelease = 0;
backBtn.justPressed = 0;
backBtn.curState = ((secondByte & BTN_BACK) ? 1:0);
if (backBtn.curState != backBtn.prevState){
if (backBtn.pressed == LOW && backBtn.curState == HIGH) backBtn.justPressed = HIGH;
if (backBtn.pressed == HIGH && backBtn.curState == LOW) backBtn.justRelease = HIGH;
backBtn.pressed = backBtn.curState;
}
backBtn.prevState = backBtn.curState;
//forward button-------------------------------
fwdBtn.justRelease = 0;
fwdBtn.justPressed = 0;
fwdBtn.curState = ((secondByte & BTN_FWD) ? 1:0);
if (fwdBtn.curState != fwdBtn.prevState){
if (fwdBtn.pressed == LOW && fwdBtn.curState == HIGH) fwdBtn.justPressed = HIGH;
if (fwdBtn.pressed == HIGH && fwdBtn.curState == LOW) fwdBtn.justRelease = HIGH;
fwdBtn.pressed = fwdBtn.curState;
}
fwdBtn.prevState = fwdBtn.curState;
and more…
thank you for your help