Commit b572fad0 authored by Toni Ruoss's avatar Toni Ruoss
Browse files

Uebung_5_ueberarbeitet

parent 2e1bdea9
......@@ -23,6 +23,7 @@ const int BUTTONPIN{7};
const int OPENPOS{180};
const int CLOSEPOS{90};
const int OPENPOS2{0}; //Aussen geöffnet
int state{S_CLOSED};
int position{CLOSEPOS};
......@@ -37,6 +38,7 @@ void setup() {
}
void loop() {
int i = 0;
switch(state) {
case S_OPEN:
if(digitalRead(BUTTONPIN) == LOW) {
......@@ -44,27 +46,60 @@ void loop() {
Serial.println("Entered Transition Closeing");
}
break;
case T_OPENING:
position++;
if(position >= OPENPOS) {
if (i == 0)
{
position++;
}
else
{
position--;
}
if(position >= OPENPOS || position <= OPENPOS2) {
state = S_OPEN;
Serial.println("Entered State OPEN");
}
if (position >= OPENPOS)
{
i=1;
}
if (position <= OPENPOS2)
{
i=0;
}
break;
case S_CLOSED:
if(digitalRead(BUTTONPIN) == HIGH) {
state = T_OPENING;
Serial.println("Entered Transition Opening");
state = T_OPENING;
Serial.println("Entered Transition Opening");
}
break;
case T_CLOSEING:
position--;
if(position <= CLOSEPOS) {
if (i == 1)
{
position--;
if(position <= CLOSEPOS) {
state = S_CLOSED;
Serial.println("Entered State CLOSE");
}
if (i == 0)
{
position++;
if(position >= CLOSEPOS) {
state = S_CLOSED;
Serial.println("Entered State CLOSE");
}
}
break;
}
myDoorDrive.write(position);
delay(10);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment