Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. //pins and constant variables
  4. const int servoPin = 5;
  5. const int servoStatePin = 13;
  6. const int ignitionPin = 2;
  7. const int ignitionStatePin = 11;
  8. const int wiperTriggerPin = 3;
  9. const int wiperTriggerStatePin = 12;
  10.  
  11. //variables
  12. bool currentStateIgnition = LOW;//stroage for current button state
  13. bool lastStateIgnition = LOW;//storage for last button state
  14. bool currentStateWiperTrigger = LOW;//stroage for current button state
  15. bool lastStateWiperTrigger = LOW;//storage for last button state
  16. bool ignitionOn = LOW;
  17. bool wipersOn = LOW;
  18. long time1 = 0;
  19. long time2 = 0;// the last time the output pin was toggled
  20. long debounce = 200;
  21. long servoInterval =200;
  22.  
  23.  
  24.  
  25. Servo myservo;
  26. int servopos;
  27.  
  28. void setup()
  29. {
  30. myservo.attach(servoPin);
  31. pinMode(ignitionPin, INPUT);
  32. pinMode(wiperTriggerPin, INPUT);
  33. pinMode(11, OUTPUT);
  34. pinMode(12, OUTPUT);
  35. pinMode(13, OUTPUT);
  36. Serial.begin(9600);
  37. }
  38.  
  39. void loop()
  40. {
  41.  
  42. currentStateIgnition = digitalRead(ignitionPin);
  43.  
  44. // if the input just went from LOW and HIGH and we've waited long enough
  45. // to ignore any noise on the circuit, toggle the output pin and remember
  46. // the time
  47. if (currentStateIgnition == HIGH && lastStateIgnition == LOW && millis() - time1 > debounce) {
  48. if (ignitionOn == HIGH)
  49. {
  50. ignitionOn = LOW;
  51. }
  52. else
  53. {
  54. ignitionOn = HIGH;
  55. }
  56. time1 = millis();
  57. }
  58. else
  59. {
  60. digitalWrite(11, ignitionOn);
  61. lastStateIgnition = currentStateIgnition;
  62. }
  63.  
  64. currentStateWiperTrigger = digitalRead(wiperTriggerPin);
  65.  
  66. if (currentStateWiperTrigger == HIGH && lastStateWiperTrigger == LOW && millis() - time2 > debounce) {
  67. if (wipersOn == HIGH)
  68. {
  69. wipersOn = LOW;
  70. }
  71. else
  72. {
  73. wipersOn = HIGH;
  74. }
  75.  
  76. time2 = millis();
  77. }
  78. else
  79. {
  80. lastStateWiperTrigger = currentStateWiperTrigger;
  81. }
  82.  
  83. if (wipersOn == HIGH && ignitionOn == HIGH )
  84. {
  85. Serial.println("Wipers active");
  86.  
  87. unsigned long millisecs30150 = millis();
  88. unsigned long mslast = 0;
  89. Serial.println(millisecs30150);
  90.  
  91. for (servopos = 30;servopos<150;servopos+=5)
  92. {
  93.  
  94.  
  95.  
  96. delay(20);
  97. myservo.write(servopos);
  98.  
  99.  
  100. }
  101. for (servopos = 150;servopos>=30;servopos -=5)
  102. {
  103.  
  104.  
  105. delay(20);
  106. myservo.write(servopos);
  107.  
  108.  
  109.  
  110. }
  111. }
  112.  
  113. else
  114. {
  115.  
  116. myservo.write(0);
  117.  
  118.  
  119.  
  120. }
  121.  
  122. if(ignitionOn==HIGH)
  123. {
  124. Serial.println("ignitionOn");
  125. digitalWrite(11, HIGH);
  126. }
  127. else
  128. {
  129. Serial.println("ignitionOff");
  130. digitalWrite(11, LOW);
  131. }
  132.  
  133. if(wipersOn==HIGH)
  134. {
  135. Serial.println("wiper button on");
  136. digitalWrite(12, HIGH);
  137. }
  138. else
  139. {
  140. Serial.println("wiper button off");
  141. digitalWrite(12, LOW);
  142. }
  143.  
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement