mof1re

Untitled

Nov 8th, 2018
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <IRremote.h>
  2. #include <Servo.h>
  3.  
  4. Servo myservo;  // create servo object to control a servo
  5. // twelve servo objects can be created on most boards
  6. int RECV_PIN = 3;
  7. IRrecv irrecv(RECV_PIN);
  8. decode_results results;
  9.  
  10. int pos = 5;    // variable to store the servo position
  11. long timeUpdate  = millis();
  12. int servospeed;
  13. bool timerStatus;
  14. bool stopStatus;
  15. bool isStopped;
  16. int timerStart;
  17. int bPause = 0;
  18. int pauseTimer;
  19.  
  20. void setup() {
  21.   myservo.attach(2);
  22.   Serial.begin(9600);
  23.   irrecv.enableIRIn(); // Start the receiver
  24.   timerStatus = false;
  25.   isStopped = true;
  26.   myservo.write(5);
  27. }
  28.  
  29. void loop() {
  30.  
  31. // MAIN LOOP
  32.   if (irrecv.decode(&results) && timeUpdate + 500 < millis()) {
  33.     irrecv.resume(); // Receive the next value
  34.    // Serial.println("Чекаем канал порта");
  35.     Serial.println(results.value);    
  36. if (results.value == 16753245)
  37. {
  38.     servospeed = 4;
  39.     bPause = 0;
  40.     Serial.println("1 speed");
  41.     if (isStopped == 1){isStopped = false;}
  42.  
  43.  
  44.   }
  45. else if (results.value == 16736925)
  46. {
  47.     servospeed = 4;
  48.      bPause = 500;
  49.     Serial.println("2 speed");
  50.     if (isStopped == 1){isStopped = 0;}
  51.  
  52.   }
  53. else if (results.value == 16769565)
  54. {
  55.     servospeed = 4;
  56.     bPause = 1000;
  57.     Serial.println("3 speed");
  58.     if (isStopped == 1){isStopped = 0;}
  59.  
  60.   }
  61. else if (results.value == 16726215)
  62. {
  63.  
  64.       timerStatus = false;
  65.       if (isStopped == 0){isStopped = 1;}
  66.       Serial.println("STOP");
  67.       myservo.write(5);
  68.   }
  69. else if (results.value == 16738455 && isStopped != 1)
  70. {
  71.     timerStatus = !timerStatus;
  72.     timerStart = millis();
  73.     Serial.print("timer is: ");
  74.     Serial.println(timerStatus);
  75.   }
  76.  else {
  77.       timeUpdate = millis();
  78.     // irrecv.resume(); // Receive the next value
  79.  
  80.   }
  81.  
  82.     timeUpdate = millis();
  83.  
  84.  
  85.   }
  86.  
  87.  
  88.  
  89.   if (pauseTimer + bPause < millis() && isStopped != 1){
  90.  
  91.     Serial.println("Двигаем мотор");
  92.       for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
  93.     // in steps of 1 degree
  94.     myservo.write(pos);              // tell servo to go to position in variable 'pos'
  95.     delay(2);                       // waits 2ms for the servo to reach the position
  96.   }
  97.   for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
  98.     myservo.write(pos);              // tell servo to go to position in variable 'pos'
  99.     delay(servospeed);                       // waits XX ms for the servo to reach the position
  100.   }
  101.     pauseTimer = millis();
  102.         Serial.println("Обнуляем таймер мотора");
  103.     }
  104.  
  105.  
  106.  
  107. } // end of loop
RAW Paste Data