// definitie van de statussen
#define BTN_SETUP 0
#define BTN_READ 1
#define BTN_START_TIMER 2
#define BTN_WACHT 3
#define BTN_INGEDRUKT 4
#define BTN_LOSGELATEN 5
//declaratie van de pinnen
#define PIN_BUT1 7
#define PIN_BUT2 6
#define PIN_LED 8
//declaratie constanten
#define INTERVAL 25 //tijdsduur in msec
#define MAX_AANTAL_BUTTONS 8
//declaratie variabelen
typedef struct {
byte btnState;
unsigned long timer;
bool toggle;
byte pin;
byte btnOldState;
} Button;
Button but1;
Button buttonlijst [MAX_AANTAL_BUTTONS] ;
//Declaratie van de fucnties
void printButton ( Button knop);
void addButton(byte pinNr, byte btnNr);
void setup( ) {
pinMode(PIN_BUT1, INPUT );
pinMode(PIN_BUT2, INPUT);
pinMode(PIN_LED, OUTPUT);
Serial.begin(115200);
addButton(7, 1);
}
for (int i = 0; i < sizeof(buttonlijst); i++) {
void loop( ) {
if (but1.btnState != but1.btnOldState) {
Serial.print( " de status is ");
Serial.println (but1.btnState);
but1.btnOldState = but1.btnState;
}
switch (but1.btnState) {
case BTN_SETUP://0
but1.btnState = BTN_READ;
break;
case BTN_READ : //1
if (digitalRead(but1.pin) == LOW) {
but1.btnState = BTN_START_TIMER;
}
break;
case BTN_START_TIMER: //2
but1.timer = millis();
but1.btnState = BTN_WACHT;
break;
case BTN_WACHT: //3
if ( digitalRead(but1.pin) == HIGH) {
but1.btnState = BTN_SETUP;
} else {
if ((millis() - but1.timer) > INTERVAL) {
but1.btnState = BTN_INGEDRUKT;
}
}
break;
case BTN_INGEDRUKT: //4
digitalWrite(PIN_LED, !digitalRead(PIN_LED));
if ( digitalRead(but1.pin) == HIGH) {
but1.btnState = BTN_LOSGELATEN;
}
break;
case BTN_LOSGELATEN: //5
but1.btnState = BTN_SETUP;
break;
default:
Serial.println("er is een foute status opgetreden");
break;
}
}
}
void printButton (Button knop) {
Serial.println(knop.btnState);
Serial.println(knop.pin);
}
void addButton(byte pinNr, byte btnNr); {
buttonlijst[brnNr].pin = pinNr;
buttonlijst[brnNr].timer = millis();
buttonlijst[brnNr].btnState = BTN_SETUP;
buttonlijst[brnNr].btnOldState = BTN_SETUP;
}