Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- //pins and constant variables
- const int servoPin = 5;
- const int servoStatePin = 13;
- const int ignitionPin = 2;
- const int ignitionStatePin = 11;
- const int wiperTriggerPin = 3;
- const int wiperTriggerStatePin = 12;
- //variables
- bool currentStateIgnition = LOW;//stroage for current button state
- bool lastStateIgnition = LOW;//storage for last button state
- bool currentStateWiperTrigger = LOW;//stroage for current button state
- bool lastStateWiperTrigger = LOW;//storage for last button state
- bool ignitionOn = LOW;
- bool wipersOn = LOW;
- long time1 = 0;
- long time2 = 0;// the last time the output pin was toggled
- long debounce = 200;
- long servoInterval =200;
- Servo myservo;
- int servopos;
- void setup()
- {
- myservo.attach(servoPin);
- pinMode(ignitionPin, INPUT);
- pinMode(wiperTriggerPin, INPUT);
- pinMode(11, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- currentStateIgnition = digitalRead(ignitionPin);
- // if the input just went from LOW and HIGH and we've waited long enough
- // to ignore any noise on the circuit, toggle the output pin and remember
- // the time
- if (currentStateIgnition == HIGH && lastStateIgnition == LOW && millis() - time1 > debounce) {
- if (ignitionOn == HIGH)
- {
- ignitionOn = LOW;
- }
- else
- {
- ignitionOn = HIGH;
- }
- time1 = millis();
- }
- else
- {
- digitalWrite(11, ignitionOn);
- lastStateIgnition = currentStateIgnition;
- }
- currentStateWiperTrigger = digitalRead(wiperTriggerPin);
- if (currentStateWiperTrigger == HIGH && lastStateWiperTrigger == LOW && millis() - time2 > debounce) {
- if (wipersOn == HIGH)
- {
- wipersOn = LOW;
- }
- else
- {
- wipersOn = HIGH;
- }
- time2 = millis();
- }
- else
- {
- lastStateWiperTrigger = currentStateWiperTrigger;
- }
- if (wipersOn == HIGH && ignitionOn == HIGH )
- {
- Serial.println("Wipers active");
- unsigned long millisecs30150 = millis();
- unsigned long mslast = 0;
- Serial.println(millisecs30150);
- for (servopos = 30;servopos<150;servopos+=5)
- {
- delay(20);
- myservo.write(servopos);
- }
- for (servopos = 150;servopos>=30;servopos -=5)
- {
- delay(20);
- myservo.write(servopos);
- }
- }
- else
- {
- myservo.write(0);
- }
- if(ignitionOn==HIGH)
- {
- Serial.println("ignitionOn");
- digitalWrite(11, HIGH);
- }
- else
- {
- Serial.println("ignitionOff");
- digitalWrite(11, LOW);
- }
- if(wipersOn==HIGH)
- {
- Serial.println("wiper button on");
- digitalWrite(12, HIGH);
- }
- else
- {
- Serial.println("wiper button off");
- digitalWrite(12, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement