SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int arrayOfPinsRelay[6] = {
  2.   2,
  3.   3,
  4.   4,
  5.   5,
  6.   6,
  7.   7
  8. };
  9. int arrayOfSwitches[6] = {
  10.   8,
  11.   9,
  12.   10,
  13.   11,
  14.   12,
  15.   13
  16. };
  17. int button = 0;
  18. int countSwitches = 6;
  19. int countRelay = 6;
  20. bool startposition = false;
  21. bool finishposition = false;
  22. bool firstStartEngine = true;
  23.  
  24.  
  25. void setup() {
  26.  
  27.   for (int i = 0; i < countRelay; i++) {
  28.     pinMode(arrayOfPinsRelay[i], OUTPUT);
  29.   }
  30.   for (int i = 0; i < countSwitches; i++) {
  31.     pinMode(arrayOfSwitches[i], INPUT);
  32.   }
  33.   if (digitalRead(13) == LOW && digitalRead(12) == LOW) {
  34.     moveToStartPosition(12, 7);
  35.     delay(1000);
  36.     moveToStartPosition(10, 5);
  37.     delay(1000);
  38.     moveToStartPosition(8, 3);
  39.     delay(1000);
  40.   } else if (digitalRead(11) == LOW && digitalRead(10) == LOW) {
  41.     moveToStartPosition(10, 5);
  42.     delay(1000);
  43.     moveToStartPosition(8, 3);
  44.     delay(1000);
  45.   } else if (digitalRead(9) == LOW && digitalRead(8) == LOW) {
  46.     moveToStartPosition(8, 3);
  47.     delay(1000);
  48.   }
  49.  
  50.   startposition = true;
  51.   firstStartEngine = false;
  52.  
  53. }
  54.  
  55. void loop() {
  56.   // put your main code here, to run repeatedly:
  57.   if (!firstStartEngine) {
  58.  
  59.       finishposition = true;
  60.       startposition = false;
  61.       if(digitalRead(9) == LOW && analogRead(button) > 500){
  62.         startMotorUp(8, 2, 9);
  63.         delay(1000);
  64.       }
  65.             if(digitalRead(11) == LOW && analogRead(button) > 500){
  66.       startMotorUp(10, 4, 11);
  67.       delay(1000);
  68.       }
  69.             if(digitalRead(13) == LOW && analogRead(button) > 500){
  70.       startMotorUp(12, 6, 13);
  71.       delay(1000);
  72.       }
  73.    
  74.  
  75.       finishposition = false;
  76.       startposition = true;
  77.                   if(digitalRead(12) == LOW && analogRead(button) == 0){
  78.       startMotorDown(13, 7, 12);
  79.       delay(1000);
  80.       }
  81.                   if(digitalRead(10) == LOW && analogRead(button) == 0){
  82.       startMotorDown(11, 5, 10);
  83.       delay(1000);
  84.       }
  85.                   if(digitalRead(8) == LOW && analogRead(button) == 0){
  86.       startMotorDown(9, 3, 8);
  87.       delay(1000);
  88.       }
  89.    
  90.   }
  91.  
  92. }
  93. void startMotorUp(int Switch, int relay, int nextSwitch) {
  94.   bool flag = false;
  95.   while (digitalRead(nextSwitch) == LOW) {
  96.     if (flag == false) {
  97.       digitalWrite(relay, HIGH);
  98.     }
  99.     flag = true;
  100.   }
  101.   digitalWrite(relay, LOW);
  102. }
  103.  
  104. void startMotorDown(int Switch, int relay, int nextSwitch) {
  105.   bool flag = false;
  106.   while (digitalRead(nextSwitch) == LOW) {
  107.     if (flag == false) {
  108.       digitalWrite(relay, HIGH);
  109.     }
  110.     flag = true;
  111.   }
  112.   digitalWrite(relay, LOW);
  113. }
  114.  
  115. void moveToStartPosition(int Switch, int relay) {
  116.   bool flag = false;
  117.   while (digitalRead(Switch) == LOW) {
  118.     if (flag == false) {
  119.       digitalWrite(relay, HIGH);
  120.     }
  121.     flag == true;
  122.   }
  123.   digitalWrite(relay, LOW);
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top