const int directionButton_Pin = 17;
const int debug_Led = 13;
int s1_waarde_eerder = 1;
const int s1_pin = 5;
long teller = 0;
bool directionButtonState = HIGH;
bool directionButtonState_Before = LOW;
bool direction_Bool = LOW;
void setSetup() {
Serial.begin(115200);
// Add Leds
pinMode(debug_Led, OUTPUT);
// Add Buttons
pinMode(directionButton_Pin, INPUT_PULLUP);
pinMode(s1_pin, INPUT_PULLUP);
}
void readdirectionButton() {
directionButtonState = digitalRead(directionButton_Pin);
if (directionButtonState != directionButtonState_Before) {
directionButtonState_Before = directionButtonState;
if (directionButtonState == LOW) {
direction_Bool = !direction_Bool; // Toggle time scaling
Serial.println("Button_directionState pressed");
Serial.println("direction_Bool = " + String(direction_Bool));
}
delay(15);
}
}
void flank_Trigger_ClassMaterial() {
int s1_waarde = digitalRead(s1_pin);
if (s1_waarde != s1_waarde_eerder) {
// we komen hier wanneer het niveau aan de input =0 en vorige niveau=1! FLANK GETRIGGERD
// Is dit geschikt voor tellers? Indrukken schakelaar verhoogt teller +1?
s1_waarde_eerder = s1_waarde;
if (s1_waarde == 0) {
// wanneer het niveau aan de input 0! NIVEAU GETRIGGERD
// Is dit geschikt voor tellers? Indrukken schakelaar verhoogt teller +1?
direction_Bool = !direction_Bool;
Serial.print("s1_waarde="); Serial.print(s1_waarde);
teller += 1;
Serial.print("teller="); Serial.println(teller);
}
delay(15);
}
}
void ledLogic() {
if(direction_Bool == HIGH) {
digitalWrite(debug_Led, HIGH);
} else {
digitalWrite(debug_Led, LOW);
}
}
void setup() {
setSetup();
}
void loop() {
readdirectionButton();
flank_Trigger_ClassMaterial();
ledLogic();
}