Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo;
- int OutButtonState = 1;
- int LastOutButtonState = 1;
- int crossingtime = 2000;
- int ButtonState = 1;
- int STATE = 0;
- int InButtonstate = 1;
- int lastInButtonState = 1;
- float time = 0;
- float time_old = 0;
- float delta_time = 0;
- int pos = 0;
- int pushButtonIn = 2;
- int pushButtonOut = 3;
- int Lightgreen = 4;
- int LightRed = 5;
- int Buzzer = 6;
- void setup()
- {
- myservo.attach(10);
- Serial.begin(9600);
- pinMode(pushButtonIn, INPUT);
- pinMode(pushButtonOut, INPUT);
- pinMode(Lightgreen, OUTPUT);
- pinMode(LightRed, OUTPUT);
- pinMode(Buzzer, OUTPUT);
- myservo.write(pos);
- }
- void loop()
- {
- switch (STATE)
- {
- case 0:
- Serial.println("STATE0");
- digitalWrite(Buzzer, LOW);
- digitalWrite(LightRed, HIGH);
- break;
- case 1:
- Serial.println("STATE1");
- digitalWrite(Buzzer, HIGH);
- for (pos = 0; pos <=90; pos += 1)
- {
- myservo.write(pos);
- delay(100);
- }
- STATE = 2;
- break;
- case 2:
- Serial.println("STATE2");
- digitalWrite(LightRed, LOW);
- digitalWrite(Lightgreen, HIGH);
- digitalWrite(Buzzer, LOW);
- delay(crossingtime);
- break;
- case 3:
- Serial.println("STATE3");
- digitalWrite(Buzzer, HIGH);
- digitalWrite(LightRed, HIGH);
- digitalWrite(Lightgreen, LOW);
- for (pos = 90; pos >= 0; pos -= 1)
- {
- myservo.write(pos);
- delay(100);
- }
- STATE = 0;
- break;
- default:
- break;
- }
- InButtonstate = digitalRead(pushButtonIn);
- if (InButtonstate != lastInButtonState)
- {
- if (InButtonstate == LOW)
- {
- if (STATE == 0)
- {
- STATE = 1;
- }
- }
- }
- lastInButtonState = InButtonstate;
- OutButtonState = digitalRead(pushButtonOut);
- if (OutButtonState != LastOutButtonState)
- {
- if (OutButtonState == LOW)
- {
- if (STATE == 2)
- {
- STATE == 3;
- }
- }
- }
- LastOutButtonState = OutButtonState;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement