#include <Toggle.h>
const byte buttonPin = 12;
const byte ledUpPin = 7;
const byte ledUDownPin = 2;
boolean IsInPositionUp = true;
Toggle sw1(buttonPin);
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
digitalWrite(ledUpPin, LOW);
digitalWrite(ledUDownPin, LOW);
pinMode(ledUpPin, OUTPUT);
pinMode(ledUDownPin, OUTPUT);
sw1.begin(buttonPin);
}
void loop() {
sw1.poll(); // must be called very often for prompt reaction to buttonpress
if ( sw1.onPress() ) { // if pressing down is detected
Serial.println();
Serial.println("pressing down detected");
if (IsInPositionUp == true) {
downPosition(); // excecute lines defined in "void "downPosition()"
}
else {
upPosition(); // excecute lines defined in "void "upPosition()"
}
}
}
void upPosition() {
Serial.println("entering function upPosition");
digitalWrite(ledUpPin, HIGH);
digitalWrite(ledUDownPin, LOW);
IsInPositionUp = true;
Serial.println("exiting function upPosition");
} // end of definition of function "upPosition()"
void downPosition() {
Serial.println("entering function downPosition");
digitalWrite(ledUpPin, LOW);
digitalWrite(ledUDownPin, HIGH);
IsInPositionUp = false; // which means is in position down
Serial.println("exiting function downPosition");
} // end of definition of function "downPosition()"