Advertisement
Guest User

Untitled

a guest
Nov 30th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. /*
  2. Ahanix1989
  3. Engages defrost and heated seat only when the car is started with remote start
  4. */
  5.  
  6. int HornTriggered = 0; // Has the horn been chirped?
  7. int BrakeTriggered = 0; // Has the brakes been pressed?
  8. int MonitorCycle = 0; // For the 'Watch for the horn' loop
  9. int DefrostCycle = 0; // For the "Watch the brakes while defrosting' loop
  10. int HornReading = 0; // Debug: The actual value detected on the horn circuit
  11. int BrakeReading = 0; // Debug: The actual value detected on the brake circuit
  12. int MonitorComplete = 0; // Only allow the cycle to run once
  13. int brightness = 0; // Fade LED
  14. int fadeAmount = 5; // Fade LED Rate
  15.  
  16. void setup() {
  17. pinMode(9, OUTPUT); // Heated Seats
  18. pinMode(10, OUTPUT); // Defrost Relay
  19. pinMode(11, OUTPUT); // Fading yellow LED ("Watching for Horn")
  20. pinMode(12, OUTPUT); // Solid red LED ("Horn detected")
  21. digitalWrite(9, HIGH); // No idea why these are reversed. Just rolling with it.
  22. digitalWrite(10, HIGH);
  23. digitalWrite(11, LOW);
  24. digitalWrite(12, LOW);
  25. }
  26.  
  27. void loop() {
  28.  
  29. Serial.begin(115200);
  30. if(MonitorComplete == 0){ // On boot, this is 0. After this first loop, it'll be 1.
  31. Serial.write("\nBeginning 10-second monitor for horn...");
  32. while(MonitorCycle < 1000){ // 1000 cycles x 10ms == 10 seconds
  33. if(digitalRead(8) == LOW){
  34. Serial.write("\n>> HORN: Low signal condition detected!");
  35. digitalWrite(12, HIGH); // Red LED -- Horn Detected
  36. HornTriggered = 1;
  37. }
  38. MonitorCycle++;
  39. analogWrite(11, brightness); // Fade the yellow LED
  40. brightness = brightness + fadeAmount;
  41. if(brightness == 0 || brightness == 255){
  42. fadeAmount = -fadeAmount;
  43. }
  44. delay(10);
  45. }
  46. Serial.write("\nMonitor Complete.");
  47. }
  48. if(MonitorComplete == 1){
  49. Serial.write("\nOn-boot monitor has already been completed. Waiting 1 minute then resetting");
  50. delay(60000);
  51. }
  52. MonitorComplete = 1; // Comment me out to loop constantly
  53. analogWrite(11, 0); // Turn the LED off
  54.  
  55. // Step 3: If the horn was triggered, activate the relays
  56. if(HornTriggered == 1){
  57. Serial.write("\nActivating Heated Seat relay in 5 seconds...");
  58. delay(5000);
  59. Serial.write("\n>>Seat relay ON");
  60. digitalWrite(9, LOW);
  61. delay(500);
  62. Serial.write("\n>>Seat relay OFF");
  63. digitalWrite(9, HIGH);
  64. Serial.write("\nActivating Defrost Relay in 2 seconds...");
  65. delay(2000);
  66. Serial.write("\n>>Defrost relay ON");
  67. digitalWrite(10, LOW);
  68. Serial.write("\n\nNow monitoring analog pin 5 for the next fifteen minutes");
  69. while(DefrostCycle < 12000){ // 12,000 cycles x 75ms == 900,000 == 15 minutes
  70. if(analogRead(A0) > 900){
  71. Serial.write("\n\n>> BRAKE: High signal condition detected! | Expected value < 900 | Actual value: ");
  72. BrakeReading = analogRead(A5);
  73. Serial.println(BrakeReading);
  74. Serial.write("\n\n");
  75. digitalWrite(12, LOW); // The other LED...
  76. break;
  77. }
  78. delay(75);
  79. DefrostCycle++;
  80. }
  81. Serial.write(">>Defrost relay OFF");
  82. digitalWrite(10, HIGH);
  83. Serial.write("\n15-minute monitor complete.");
  84.  
  85. }
  86.  
  87. if(HornTriggered == 0){
  88. Serial.write("\n\nHorn signal never detected.\nAssuming normal key-in start was performed.");
  89. }
  90.  
  91. Serial.write("\n\nResetting all the variables...");
  92. HornTriggered = 0;
  93. BrakeTriggered = 0;
  94. MonitorCycle = 0;
  95. DefrostCycle = 0;
  96. Serial.write("\n>>Resetting in 10 seconds...\n\n");
  97. delay(10000);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement